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