Skip to content

Commit b22b08c

Browse files
committed
[cling] Make cling::utils::Lookup::Named look into using directives
1 parent 39fa290 commit b22b08c

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

interpreter/cling/lib/Utils/AST.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,15 @@ namespace utils {
15011501
// No definition, no lookup result.
15021502
return;
15031503
}
1504-
S->LookupQualifiedName(R, const_cast<DeclContext*>(primaryWithin));
1504+
bool res =
1505+
S->LookupQualifiedName(R, const_cast<DeclContext*>(primaryWithin));
1506+
1507+
// If the lookup fails and the context is a namespace, try to lookup in
1508+
// the namespaces by setting NotForRedeclaration.
1509+
if (!res && primaryWithin->isNamespace()) {
1510+
R.setRedeclarationKind(Sema::NotForRedeclaration);
1511+
S->LookupQualifiedName(R, const_cast<DeclContext*>(primaryWithin));
1512+
}
15051513
}
15061514
}
15071515

interpreter/cling/test/.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DisableFormat: true

interpreter/cling/test/Lookup/named.C

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ namespace AnotherNext {
3737
class Inside_AnotherNext {};
3838
}
3939

40+
namespace A {
41+
class C;
42+
}
43+
namespace B {
44+
using namespace A;
45+
}
46+
4047
.rawInput 0
4148

4249
// ROOT-6095: names introduced in a scopeless enum should be available in the
@@ -106,3 +113,20 @@ decl
106113
decl = utils::Lookup::Named(&S, "EvenLess", context);
107114
decl
108115
//CHECK: (const clang::NamedDecl *) {{0x0*$|nullptr}}
116+
117+
// Lookup the declaration for namespace B.
118+
decl = utils::Lookup::Named(&S, "B", nullptr);
119+
decl
120+
// CHECK: (const clang::NamedDecl *) 0x{{[1-9a-f][0-9a-f]*$}}
121+
122+
const clang::DeclContext* contextB = llvm::dyn_cast<clang::DeclContext>(decl);
123+
contextB
124+
// CHECK: (const clang::DeclContext *) 0x{{[1-9a-f][0-9a-f]*$}}
125+
126+
// Lookup 'C' from namespace B.
127+
decl = utils::Lookup::Named(&S, "C", contextB);
128+
decl
129+
// CHECK: (const clang::NamedDecl *) 0x{{[1-9a-f][0-9a-f]*$}}
130+
131+
decl->getQualifiedNameAsString()
132+
// CHECK: (std::string) "A::C"

0 commit comments

Comments
 (0)