Skip to content

Commit f469002

Browse files
sudo-pandavgvassilev
authored andcommitted
Fix GetScope returning TypedefDecl of non scopes
1 parent ae3ccbe commit f469002

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

include/clang/Interpreter/CppInterOp.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,9 @@ namespace Cpp {
224224
/// underlying decl is not a class it returns the input unchanged.
225225
TCppScope_t GetUnderlyingScope(TCppScope_t scope);
226226

227-
/// Gets the namespace or class for the name passed as a parameter,
228-
/// and if the parent is not passed, then global scope will be assumed.
227+
/// Gets the namespace or class (by stripping typedefs) for the name
228+
/// passed as a parameter, and if the parent is not passed,
229+
/// then global scope will be assumed.
229230
TCppScope_t GetScope(const std::string &name, TCppScope_t parent = 0);
230231

231232
/// When the namespace is known, then the parent doesn't need

lib/Interpreter/CppInterOp.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -502,11 +502,13 @@ namespace Cpp {
502502

503503
auto *ND = (NamedDecl*)GetNamed(name, parent);
504504

505-
if (!(ND == (NamedDecl *)-1) &&
506-
(llvm::isa_and_nonnull<NamespaceDecl>(ND) ||
507-
llvm::isa_and_nonnull<RecordDecl>(ND) ||
508-
llvm::isa_and_nonnull<ClassTemplateDecl>(ND) ||
509-
llvm::isa_and_nonnull<TypedefDecl>(ND)))
505+
ND = llvm::dyn_cast_or_null<NamedDecl>(GetUnderlyingScope(ND));
506+
507+
if (!ND || ND == (NamedDecl *) -1)
508+
return 0;
509+
510+
if (llvm::isa<NamespaceDecl>(ND) || llvm::isa<RecordDecl>(ND) ||
511+
llvm::isa<ClassTemplateDecl>(ND))
510512
return (TCppScope_t)(ND->getCanonicalDecl());
511513

512514
return 0;

0 commit comments

Comments
 (0)