[PATCH] D19721: Fix crash in BuildCXXDefaultInitExpr.
Reid Kleckner via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 29 11:12:50 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268082: Fix crash in BuildCXXDefaultInitExpr. (authored by rnk).
Changed prior to commit:
http://reviews.llvm.org/D19721?vs=55580&id=55631#toc
Repository:
rL LLVM
http://reviews.llvm.org/D19721
Files:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/pr27047-default-init-expr-name-conflict.cpp
Index: cfe/trunk/test/SemaCXX/pr27047-default-init-expr-name-conflict.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/pr27047-default-init-expr-name-conflict.cpp
+++ cfe/trunk/test/SemaCXX/pr27047-default-init-expr-name-conflict.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s
+
+template <typename T>
+struct A {
+ // Used to crash when field was named after class.
+ int A = 0;
+};
+A<int> a;
Index: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp
@@ -11412,8 +11412,19 @@
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();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19721.55631.patch
Type: text/x-patch
Size: 1661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160429/cb9f7e6c/attachment.bin>
More information about the cfe-commits
mailing list