Skip to content

Commit 8969498

Browse files
committed
[include-cleaner] Mark RecordDecls referenced in UsingDecls as explicit
We were reporting ambigious references from using declarations as user can be depending on different overloads of a function just because they are visible in the TU. This doesn't apply to records, or primary templates as declaration being referenced in such cases is unambigious, the ambiguity applies to specializations though. Hence this patch returns an explicit reference to record decls and primary templates of those.
1 parent fee4836 commit 8969498

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
203203
bool VisitUsingDecl(UsingDecl *UD) {
204204
for (const auto *Shadow : UD->shadows()) {
205205
auto *TD = Shadow->getTargetDecl();
206-
auto IsUsed = TD->isUsed() || TD->isReferenced();
206+
auto IsUsed = TD->isUsed() || TD->isReferenced() || !TD->getAsFunction();
207207
report(UD->getLocation(), TD,
208208
IsUsed ? RefType::Explicit : RefType::Ambiguous);
209209

clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ TEST(WalkAST, TemplateSpecializationsFromUsingDecl) {
255255
// Class templates
256256
testWalk(R"cpp(
257257
namespace ns {
258-
template<class T> class $ambiguous^Z {}; // primary template
258+
template<class T> class $explicit^Z {}; // primary template
259259
template<class T> class $ambiguous^Z<T*> {}; // partial specialization
260260
template<> class $ambiguous^Z<int> {}; // full specialization
261261
}
@@ -265,7 +265,7 @@ template<> class $ambiguous^Z<int> {}; // full specialization
265265
// Var templates
266266
testWalk(R"cpp(
267267
namespace ns {
268-
template<class T> T $ambiguous^foo; // primary template
268+
template<class T> T $explicit^foo; // primary template
269269
template<class T> T $ambiguous^foo<T*>; // partial specialization
270270
template<> int* $ambiguous^foo<int>; // full specialization
271271
}
@@ -335,7 +335,12 @@ TEST(WalkAST, Using) {
335335
testWalk(R"cpp(
336336
namespace ns {
337337
template<class T>
338-
class $ambiguous^Y {};
338+
class $explicit^Y {};
339+
})cpp",
340+
"using ns::^Y;");
341+
testWalk(R"cpp(
342+
namespace ns {
343+
class $explicit^Y {};
339344
})cpp",
340345
"using ns::^Y;");
341346
testWalk(R"cpp(

0 commit comments

Comments
 (0)