diff options
author | Reid Kleckner <rnk@google.com> | 2016-04-29 18:06:53 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2016-04-29 18:06:53 +0000 |
commit | 327b06400fc208fbd2da720383733d09568ae5f3 (patch) | |
tree | 4448a5a26d61fbb67a79c8d6ec47f600e9618394 /clang/lib/Sema | |
parent | f608c054523232ec28afba73619a29529450aaa9 (diff) | |
download | bcm5719-llvm-327b06400fc208fbd2da720383733d09568ae5f3.tar.gz bcm5719-llvm-327b06400fc208fbd2da720383733d09568ae5f3.zip |
Fix crash in BuildCXXDefaultInitExpr.
Fix crash in BuildCXXDefaultInitExpr when member of template class has
same name as the class itself.
Based on patch by Raphael "Teemperor" Isemann!
Differential Revision: http://reviews.llvm.org/D19721
llvm-svn: 268082
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 40be8d64562..21db3be3ccf 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -11412,8 +11412,19 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field) { CXXRecordDecl *ClassPattern = ParentRD->getTemplateInstantiationPattern(); DeclContext::lookup_result Lookup = ClassPattern->lookup(Field->getDeclName()); - assert(Lookup.size() == 1); - FieldDecl *Pattern = cast<FieldDecl>(Lookup[0]); + + // Lookup can return at most two results: the pattern for the field, or the + // injected class name of the parent record. No other member can have the + // same name as the field. + assert(!Lookup.empty() && Lookup.size() <= 2 && + "more than two lookup results for field name"); + FieldDecl *Pattern = dyn_cast<FieldDecl>(Lookup[0]); + if (!Pattern) { + assert(isa<CXXRecordDecl>(Lookup[0]) && + "cannot have other non-field member with same name"); + Pattern = cast<FieldDecl>(Lookup[1]); + } + if (InstantiateInClassInitializer(Loc, Field, Pattern, getTemplateInstantiationArgs(Field))) return ExprError(); |