Skip to content

Commit

Permalink
Harvest provided types from alias template args
Browse files Browse the repository at this point in the history
  • Loading branch information
bolshakov-a committed Jan 21, 2024
1 parent e7a3084 commit bb1b82a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion iwyu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4332,14 +4332,20 @@ class IwyuAstConsumer

set<const Type*> GetProvidedByTplArg(const Type* type) {
set<const Type*> res;
if (const auto* elaborated = dyn_cast_or_null<ElaboratedType>(type)) {
if (!type)
return res;
if (const auto* elaborated = dyn_cast<ElaboratedType>(type)) {
const NestedNameSpecifier* nns = elaborated->getQualifier();
while (nns) {
if (const Type* host = nns->getAsType())
InsertAllInto(GetTplInstData(host).provided_types, &res);
nns = nns->getPrefix();
}
}
if (const auto* tpl_spec = type->getAs<TemplateSpecializationType>()) {
if (tpl_spec->isTypeAlias())
InsertAllInto(GetTplInstData(tpl_spec).provided_types, &res);
}
return res;
}

Expand Down
5 changes: 5 additions & 0 deletions tests/cxx/alias_template.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ constexpr auto s = sizeof(ic);
// IWYU: IndirectClass needs a declaration
Identity<IndirectClass>* pic = nullptr;

// IWYU: IndirectClass is...*indirect.h
using Providing = IndirectClass;

Identity<Providing> type_is_provided_by_arg;

template<class T> struct FullUseTemplateArgInSizeof {
char argument[sizeof(T)];
};
Expand Down
5 changes: 5 additions & 0 deletions tests/cxx/iwyu_stricter_than_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<IndirectStruct3> tnpanu;

TemplateProvidedArgumentUsed<DoesNotForwardDeclareAndIncludes>
argument_provided;
// IWYU: IndirectStruct2 is...*iwyu_stricter_than_cpp-i2.h
TemplateProvidedArgumentUsed<DoesEverythingRight> argument_not_provided;
}

void TestAutocast() {
Expand Down

0 comments on commit bb1b82a

Please sign in to comment.