diff --git a/iwyu.cc b/iwyu.cc index 573a7929e..32ce921d3 100644 --- a/iwyu.cc +++ b/iwyu.cc @@ -4332,7 +4332,9 @@ class IwyuAstConsumer set GetProvidedByTplArg(const Type* type) { set res; - if (const auto* elaborated = dyn_cast_or_null(type)) { + if (!type) + return res; + if (const auto* elaborated = dyn_cast(type)) { const NestedNameSpecifier* nns = elaborated->getQualifier(); while (nns) { if (const Type* host = nns->getAsType()) @@ -4340,6 +4342,10 @@ class IwyuAstConsumer nns = nns->getPrefix(); } } + if (const auto* tpl_spec = type->getAs()) { + if (tpl_spec->isTypeAlias()) + InsertAllInto(GetTplInstData(tpl_spec).provided_types, &res); + } return res; } diff --git a/tests/cxx/alias_template.cc b/tests/cxx/alias_template.cc index d0256604c..d442c6ae3 100644 --- a/tests/cxx/alias_template.cc +++ b/tests/cxx/alias_template.cc @@ -24,6 +24,11 @@ constexpr auto s = sizeof(ic); // IWYU: IndirectClass needs a declaration Identity* pic = nullptr; +// IWYU: IndirectClass is...*indirect.h +using Providing = IndirectClass; + +Identity type_is_provided_by_arg; + template struct FullUseTemplateArgInSizeof { char argument[sizeof(T)]; }; diff --git a/tests/cxx/iwyu_stricter_than_cpp.cc b/tests/cxx/iwyu_stricter_than_cpp.cc index 215103779..8866d721c 100644 --- a/tests/cxx/iwyu_stricter_than_cpp.cc +++ b/tests/cxx/iwyu_stricter_than_cpp.cc @@ -274,6 +274,11 @@ void TestAliasTemplates() { // IWYU: IndirectStruct2 is...*iwyu_stricter_than_cpp-i2.h // IWYU: TplIndirectStruct3 is...*iwyu_stricter_than_cpp-i5.h TemplateNotProvidedArgumentNotUsed tnpanu; + + TemplateProvidedArgumentUsed + argument_provided; + // IWYU: IndirectStruct2 is...*iwyu_stricter_than_cpp-i2.h + TemplateProvidedArgumentUsed argument_not_provided; } void TestAutocast() {