Skip to content

Commit e2c1844

Browse files
using getFirstDecl for TranslationUnitDecl for consistent pointers
1 parent 57d09bd commit e2c1844

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/Interpreter/CppInterOp.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ namespace Cpp {
498498

499499
TCppScope_t GetGlobalScope()
500500
{
501-
return getSema().getASTContext().getTranslationUnitDecl();
501+
return getSema().getASTContext().getTranslationUnitDecl()->getFirstDecl();
502502
}
503503

504504
static Decl *GetScopeFromType(QualType QT) {
@@ -604,8 +604,12 @@ namespace Cpp {
604604
if (!ParentDC)
605605
return 0;
606606

607-
return (TCppScope_t) clang::Decl::castFromDeclContext(
608-
ParentDC)->getCanonicalDecl();
607+
auto* P = clang::Decl::castFromDeclContext(ParentDC)->getCanonicalDecl();
608+
609+
if (auto* TU = llvm::dyn_cast_or_null<TranslationUnitDecl>(P))
610+
return (TCppScope_t)TU->getFirstDecl();
611+
612+
return (TCppScope_t)P;
609613
}
610614

611615
TCppIndex_t GetNumBases(TCppScope_t klass)

0 commit comments

Comments
 (0)