This is an archive of the discontinued LLVM Phabricator instance.

[include-cleaner] Report all specializations if the primary template is introduced by a using-decl.
ClosedPublic

Authored by hokein on Jun 7 2023, 12:12 AM.

Details

Summary

This will fix unused-include false positive.

// primary.h
namespace ns {
template<class T1, class T2> class Z {}; // primary template
}

// partial.h
namespace ns {
template<class T> class Z<T, T*> {};     // partial specialization
}

// main.cpp

using ns::Z; // refs to the primary
void k() {
  Z<int, int*> z; // use the partial specialization
}

Diff Detail

Event Timeline

hokein created this revision.Jun 7 2023, 12:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2023, 12:12 AM
hokein requested review of this revision.Jun 7 2023, 12:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2023, 12:12 AM
kadircet accepted this revision.Jun 7 2023, 1:26 AM

thanks!

clang-tools-extra/include-cleaner/lib/WalkAST.cpp
176

nit: prefer early exit

176

s/dyn_cast/llvm::dyn_cast

179

s/SmallVector/llvm::SmallVector

202

s/dyn_cast/llvm::dyn_cast

clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
257–272

i think we can merge these into a single test with something like:

namespace ns {
  template <typename T> struct Z {};
  template <typename T> struct Z<T*> {};
  template <> struct Z<int> {};
}

using ns::Z; // uses all 3.

same applies to var template tests.

This revision is now accepted and ready to land.Jun 7 2023, 1:26 AM
hokein updated this revision to Diff 529215.Jun 7 2023, 1:53 AM
hokein marked 5 inline comments as done.

address review comments.

This revision was landed with ongoing or failed builds.Jun 7 2023, 1:59 AM
This revision was automatically updated to reflect the committed changes.