From f9f4fd2eef993ed063f0ac181623023ec7350c7f Mon Sep 17 00:00:00 2001 From: Bolshakov Date: Tue, 24 Jan 2023 22:04:05 +0300 Subject: [PATCH] Test reporting types hidden in tpl arguments The full type use reporting in the three covered cases is ensured with excessive `CanIgnoreType` calls which check not only the type to be reported but also the type before dereferencing (which occurs to be in the resugaring map). This approach should be refactored in subsequent commits. --- tests/cxx/member_expr.cc | 22 ++++++++++++++++++++++ tests/cxx/operator_new.cc | 11 +++++++++++ tests/cxx/sizeof_reference.cc | 16 ++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/tests/cxx/member_expr.cc b/tests/cxx/member_expr.cc index 0ec420a..3584275 100644 --- a/tests/cxx/member_expr.cc +++ b/tests/cxx/member_expr.cc @@ -120,6 +120,27 @@ void ViaMacro(const IndirectTemplate& ic) { IC_CALL_METHOD; } +// Test type use with member expression inside a template. + +template +void MemberExprInside() { + T* t = nullptr; + (*t)->Method(); +} + +class IndirectClass; // IndirectClassPtr doesn't provide IndirectClass. +typedef IndirectClass* IndirectClassPtr; + +namespace ns { +using ::IndirectClassPtr; +} + +void Fn() { + // IndirectClass is hidden by a pointer and (at least) two levels of sugar. + // IWYU: IndirectClass is...*indirect.h + MemberExprInside(); +} + /**** IWYU_SUMMARY tests/cxx/member_expr.cc should add these lines: @@ -127,6 +148,7 @@ tests/cxx/member_expr.cc should add these lines: tests/cxx/member_expr.cc should remove these lines: - #include "tests/cxx/direct.h" // lines XX-XX +- class IndirectClass; // lines XX-XX The full include-list for tests/cxx/member_expr.cc: #include "tests/cxx/indirect.h" // for IndirectClass, IndirectTemplate diff --git a/tests/cxx/operator_new.cc b/tests/cxx/operator_new.cc index fb90556..4523f2f 100644 --- a/tests/cxx/operator_new.cc +++ b/tests/cxx/operator_new.cc @@ -43,6 +43,12 @@ void ExpressionsBuiltinTypes() { } // New- and delete-expressions with user-defined types. + +template +void TplFnWithDelete(T p) { + delete p; +} + void ExpressionsUserTypes() { // IWYU: IndirectClass needs a declaration // IWYU: IndirectClass is...*indirect.h @@ -55,6 +61,11 @@ void ExpressionsUserTypes() { IndirectClass* arr = new IndirectClass[4]; // IWYU: IndirectClass is...*indirect.h delete[] arr; + + // Hide the pointer type behind "decltype" sugar. + decltype(elem) elem2 = nullptr; + // IWYU: IndirectClass is...*indirect.h + TplFnWithDelete(elem2); } // Aligned allocation uses operator new(size_t, std::align_val_t) under the diff --git a/tests/cxx/sizeof_reference.cc b/tests/cxx/sizeof_reference.cc index fe5256c..99e42a0 100644 --- a/tests/cxx/sizeof_reference.cc +++ b/tests/cxx/sizeof_reference.cc @@ -103,6 +103,22 @@ SizeofTakingStructTplRef2 sizeof_taking_struct5; // IWYU: IndirectClass needs a declaration SizeofTakingStructTplRef2 sizeof_taking_struct6; +// The same with some sugar. + +// IWYU: IndirectClass is...*indirect.h +SizeofTakingStruct sizeof_taking_struct7; + +// IWYU: IndirectClass is...*indirect.h +SizeofTakingStructRef sizeof_taking_struct8; + +SizeofTakingStructTpl sizeof_taking_struct9; + +SizeofTakingStructTplRef sizeof_taking_struct10; + +// IWYU: IndirectClass is...*indirect.h +SizeofTakingStructTplRef2 sizeof_taking_struct11; + +SizeofTakingStructTplRef2 sizeof_taking_struct12; /**** IWYU_SUMMARY