diff options
author | Chuanqi Xu <yedeng.yd@linux.alibaba.com> | 2022-01-11 10:15:46 +0800 |
---|---|---|
committer | Chuanqi Xu <yedeng.yd@linux.alibaba.com> | 2022-01-11 10:16:26 +0800 |
commit | d9d63fc1088c22129cde9c3d3a84f356c875190e (patch) | |
tree | e9aa277e1fd9018f4d31b25f43d9bcff3e12436d /clang/lib/AST/DeclBase.cpp | |
parent | 9ef2175f812a9308cbcefc4729f6a6c9e75c2b6f (diff) | |
download | llvm-d9d63fc1088c22129cde9c3d3a84f356c875190e.zip llvm-d9d63fc1088c22129cde9c3d3a84f356c875190e.tar.gz llvm-d9d63fc1088c22129cde9c3d3a84f356c875190e.tar.bz2 |
[AST] lookup in parent DeclContext for transparent DeclContext
The compiler would crash if we lookup for name in transparent decl
context. See the tests attached for example.
I think this should make sense since the member declared in transparent
DeclContext are semantically defined in the enclosing (non-transparent)
DeclContext, this is the definition for transparent DeclContext.
Reviewed By: erichkeane
Differential Revision: https://reviews.llvm.org/D116792
Diffstat (limited to 'clang/lib/AST/DeclBase.cpp')
-rw-r--r-- | clang/lib/AST/DeclBase.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 52b8a457..98a5c6b 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -1644,9 +1644,9 @@ void DeclContext::buildLookupImpl(DeclContext *DCtx, bool Internal) { DeclContext::lookup_result DeclContext::lookup(DeclarationName Name) const { - assert(getDeclKind() != Decl::LinkageSpec && - getDeclKind() != Decl::Export && - "should not perform lookups into transparent contexts"); + // For transparent DeclContext, we should lookup in their enclosing context. + if (getDeclKind() == Decl::LinkageSpec || getDeclKind() == Decl::Export) + return getParent()->lookup(Name); const DeclContext *PrimaryContext = getPrimaryContext(); if (PrimaryContext != this) |