summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBolshakov <bolsh.andrey@yandex.ru>2022-07-16 17:07:11 +0300
committerKim Gräsman <kim.grasman@gmail.com>2022-07-23 13:18:27 +0200
commit0f7a7aba8c949f97b579a4643367e9b9ffddf7c2 (patch)
tree04db9bcf220182f90dccaa4065bf748b1af71509
parente0ae900e84d9ec455d1694a006b435532724808c (diff)
Report aliased template parameter
Template-nested typedef can't be responsible for any parameter of the template, because an exact type is known only on template specialization.
-rw-r--r--iwyu.cc3
-rw-r--r--tests/cxx/typedef_in_template.cc8
2 files changed, 6 insertions, 5 deletions
diff --git a/iwyu.cc b/iwyu.cc
index dcf7b58..e3849cf 100644
--- a/iwyu.cc
+++ b/iwyu.cc
@@ -1433,7 +1433,8 @@ class IwyuBaseAstVisitor : public BaseAstVisitor<Derived> {
const Type* deref_type
= RemovePointersAndReferencesAsWritten(underlying_type);
- if (CodeAuthorWantsJustAForwardDeclare(deref_type, GetLocation(decl))) {
+ if (isa<SubstTemplateTypeParmType>(deref_type) ||
+ CodeAuthorWantsJustAForwardDeclare(deref_type, GetLocation(decl))) {
retval.insert(deref_type);
// TODO(csilvers): include template type-args if appropriate.
// This requires doing an iwyu visit of the instantiated
diff --git a/tests/cxx/typedef_in_template.cc b/tests/cxx/typedef_in_template.cc
index fa26886..37bbadf 100644
--- a/tests/cxx/typedef_in_template.cc
+++ b/tests/cxx/typedef_in_template.cc
@@ -43,7 +43,7 @@ void Declarations() {
// of corresponding template argument type.
// TODO: full Class2 type info isn't needed here
- // TODO: IWYU: Class1 is...*typedef_in_template-i1.h
+ // IWYU: Class1 is...*typedef_in_template-i1.h
// IWYU: Class1 needs a declaration
// IWYU: Class2 is...*typedef_in_template-i2.h
// IWYU: Class2 needs a declaration
@@ -55,7 +55,7 @@ void Declarations() {
Container<Class1, Class2>::pair_type pt;
// TODO: full Class2 type info isn't needed here
- // TODO: IWYU: Class1 is...*typedef_in_template-i1.h
+ // IWYU: Class1 is...*typedef_in_template-i1.h
// IWYU: Class1 needs a declaration
// IWYU: Class2 is...*typedef_in_template-i2.h
// IWYU: Class2 needs a declaration
@@ -110,8 +110,8 @@ NestedUseOfAliasedParameter<IndirectClass> c;
tests/cxx/typedef_in_template.cc should add these lines:
#include "tests/cxx/indirect.h"
+#include "tests/cxx/typedef_in_template-i1.h"
#include "tests/cxx/typedef_in_template-i2.h"
-class Class1;
tests/cxx/typedef_in_template.cc should remove these lines:
- #include "tests/cxx/direct.h" // lines XX-XX
@@ -120,7 +120,7 @@ tests/cxx/typedef_in_template.cc should remove these lines:
The full include-list for tests/cxx/typedef_in_template.cc:
#include "tests/cxx/indirect.h" // for IndirectClass
+#include "tests/cxx/typedef_in_template-i1.h" // for Class1
#include "tests/cxx/typedef_in_template-i2.h" // for Class2, Pair
-class Class1;
***** IWYU_SUMMARY */