summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--iwyu.cc6
-rw-r--r--tests/cxx/explicit_instantiation2-template_helpers.h8
-rw-r--r--tests/cxx/explicit_instantiation2-template_short.h2
-rw-r--r--tests/cxx/explicit_instantiation2.cc6
4 files changed, 19 insertions, 3 deletions
diff --git a/iwyu.cc b/iwyu.cc
index 18e7ed1..5dbb34b 100644
--- a/iwyu.cc
+++ b/iwyu.cc
@@ -3206,7 +3206,7 @@ class InstantiatedTemplateVisitor
ast_node != caller_ast_node_; ast_node = ast_node->parent()) {
if (preprocessor_info().PublicHeaderIntendsToProvide(
GetFileEntry(ast_node->GetLocation()),
- GetFileEntry(decl)))
+ GetFileEntry(decl->getLocation())))
return ast_node->GetLocation();
}
return SourceLocation(); // an invalid source-loc
@@ -3218,8 +3218,10 @@ class InstantiatedTemplateVisitor
bool IsProvidedByTemplate(const Type* type) const {
type = RemoveSubstTemplateTypeParm(type);
type = RemovePointersAndReferences(type); // get down to the decl
- if (const NamedDecl* decl = TypeToDeclAsWritten(type))
+ if (const NamedDecl* decl = TypeToDeclAsWritten(type)) {
+ decl = GetDefinitionAsWritten(decl);
return GetLocOfTemplateThatProvides(decl).isValid();
+ }
return true; // we always provide non-decl types like int, etc.
}
diff --git a/tests/cxx/explicit_instantiation2-template_helpers.h b/tests/cxx/explicit_instantiation2-template_helpers.h
index 5068fe1..71c3679 100644
--- a/tests/cxx/explicit_instantiation2-template_helpers.h
+++ b/tests/cxx/explicit_instantiation2-template_helpers.h
@@ -37,4 +37,12 @@ class TemplateTemplateArgShortFwd {
T<short>* t;
};
+template <class T>
+class ProvidedTemplate {};
+
+template <class U = short, class T = ProvidedTemplate<U>>
+class TemplateAsDefaultFullProvided {
+ T t;
+};
+
#endif // INCLUDE_WHAT_YOU_USE_TESTS_CXX_EXPLICIT_INSTANTIATION2_TEMPLATE_HELPERS_H_
diff --git a/tests/cxx/explicit_instantiation2-template_short.h b/tests/cxx/explicit_instantiation2-template_short.h
index 0569349..5bae3fe 100644
--- a/tests/cxx/explicit_instantiation2-template_short.h
+++ b/tests/cxx/explicit_instantiation2-template_short.h
@@ -12,4 +12,6 @@
extern template class Template<short>;
+extern template class ProvidedTemplate<short>;
+
#endif // INCLUDE_WHAT_YOU_USE_TESTS_CXX_EXPLICIT_INSTANTIATION2_TEMPLATE_SHORT_H_
diff --git a/tests/cxx/explicit_instantiation2.cc b/tests/cxx/explicit_instantiation2.cc
index 754ddc7..168d6c8 100644
--- a/tests/cxx/explicit_instantiation2.cc
+++ b/tests/cxx/explicit_instantiation2.cc
@@ -29,6 +29,8 @@
// 6: Fwd-decl use in a template, provided as a default parameter.
// 9: Implicit instantiation of Template<int>
// 10: Specialization of Template<T>
+// 11: Explicit instantiation with a dependent instantiation declaration, but
+// provided by the template helper itself.
// IWYU: Template is...*explicit_instantiation-template.h
@@ -81,6 +83,8 @@ template <> class Template<char> {};
TemplateAsDefaultFull<char> t10; // 10
+TemplateAsDefaultFullProvided<> t11; // 11
+
/**** IWYU_SUMMARY
tests/cxx/explicit_instantiation2.cc should add these lines:
@@ -93,7 +97,7 @@ tests/cxx/explicit_instantiation2.cc should remove these lines:
The full include-list for tests/cxx/explicit_instantiation2.cc:
#include "explicit_instantiation-template.h" // for Template
-#include "explicit_instantiation2-template_helpers.h" // for FullUseArg, FwdDeclUseArg, TemplateAsDefaultFull, TemplateAsDefaultFwd, TemplateTemplateArgShortFull, TemplateTemplateArgShortFwd
+#include "explicit_instantiation2-template_helpers.h" // for FullUseArg, FwdDeclUseArg, TemplateAsDefaultFull, TemplateAsDefaultFullProvided, TemplateAsDefaultFwd, TemplateTemplateArgShortFull, TemplateTemplateArgShortFwd
#include "explicit_instantiation2-template_short.h" // for Template
***** IWYU_SUMMARY */