File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 13
13
#include " clang/AST/ASTContext.h"
14
14
#include " clang/AST/Decl.h"
15
15
#include " clang/AST/DeclBase.h"
16
+ #include " clang/AST/DeclCXX.h"
16
17
#include " clang/Basic/Builtins.h"
17
18
#include " clang/Basic/FileEntry.h"
18
19
#include " clang/Basic/SourceLocation.h"
@@ -116,6 +117,8 @@ std::optional<tooling::stdlib::Header>
116
117
headerForAmbiguousStdSymbol (const NamedDecl *ND) {
117
118
if (!ND->isInStdNamespace ())
118
119
return {};
120
+ if (auto * USD = llvm::dyn_cast<UsingShadowDecl>(ND))
121
+ ND = USD->getTargetDecl ();
119
122
const auto *FD = ND->getAsFunction ();
120
123
if (!FD)
121
124
return std::nullopt;
Original file line number Diff line number Diff line change 11
11
#include " clang-include-cleaner/Analysis.h"
12
12
#include " clang-include-cleaner/Record.h"
13
13
#include " clang-include-cleaner/Types.h"
14
+ #include " clang/AST/Expr.h"
14
15
#include " clang/AST/RecursiveASTVisitor.h"
15
16
#include " clang/Basic/FileEntry.h"
16
17
#include " clang/Basic/FileManager.h"
@@ -587,6 +588,36 @@ TEST_F(HeadersForSymbolTest, AmbiguousStdSymbols) {
587
588
}
588
589
}
589
590
591
+ TEST_F (HeadersForSymbolTest, AmbiguousStdSymbolsUsingShadow) {
592
+ Inputs.Code = R"cpp(
593
+ void remove(char*);
594
+ namespace std { using ::remove; }
595
+
596
+ void k() {
597
+ std::remove("abc");
598
+ }
599
+ )cpp" ;
600
+ buildAST ();
601
+
602
+ // Find the DeclRefExpr in the std::remove("abc") function call.
603
+ struct Visitor : public RecursiveASTVisitor <Visitor> {
604
+ const DeclRefExpr *Out = nullptr ;
605
+ bool VisitDeclRefExpr (const DeclRefExpr *DRE) {
606
+ EXPECT_TRUE (Out == nullptr ) << " Found multiple DeclRefExpr!" ;
607
+ Out = DRE;
608
+ return true ;
609
+ }
610
+ };
611
+ Visitor V;
612
+ V.TraverseDecl (AST->context ().getTranslationUnitDecl ());
613
+ ASSERT_TRUE (V.Out ) << " Couldn't find a DeclRefExpr!" ;
614
+ EXPECT_THAT (headersForSymbol (*(V.Out ->getFoundDecl ()),
615
+ AST->sourceManager (), &PI),
616
+ UnorderedElementsAre (
617
+ Header (*tooling::stdlib::Header::named (" <cstdio>" ))));
618
+ }
619
+
620
+
590
621
TEST_F (HeadersForSymbolTest, StandardHeaders) {
591
622
Inputs.Code = " void assert();" ;
592
623
buildAST ();
You can’t perform that action at this time.
0 commit comments