r272247 - [Sema] Don't crash when a field w/ a mem-initializer clashes with a record name

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 8 22:26:57 PDT 2016


Author: majnemer
Date: Thu Jun  9 00:26:56 2016
New Revision: 272247

URL: http://llvm.org/viewvc/llvm-project?rev=272247&view=rev
Log:
[Sema] Don't crash when a field w/ a mem-initializer clashes with a record name

It is possible for a field and a class to have the same name.  In such
cases, performing lookup for the field might return a result set with
more than one entry.  An overzealous assertion fired, causing us to
crash instead of using the non-class lookup result.

This fixes PR28060.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
    cfe/trunk/test/SemaCXX/member-init.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=272247&r1=272246&r2=272247&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Thu Jun  9 00:26:56 2016
@@ -2637,8 +2637,7 @@ Sema::InstantiateClassMembers(SourceLoca
             Instantiation->getTemplateInstantiationPattern();
         DeclContext::lookup_result Lookup =
             ClassPattern->lookup(Field->getDeclName());
-        assert(Lookup.size() == 1);
-        FieldDecl *Pattern = cast<FieldDecl>(Lookup[0]);
+        FieldDecl *Pattern = cast<FieldDecl>(Lookup.front());
         InstantiateInClassInitializer(PointOfInstantiation, Field, Pattern,
                                       TemplateArgs);
       }

Modified: cfe/trunk/test/SemaCXX/member-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/member-init.cpp?rev=272247&r1=272246&r2=272247&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/member-init.cpp (original)
+++ cfe/trunk/test/SemaCXX/member-init.cpp Thu Jun  9 00:26:56 2016
@@ -192,3 +192,13 @@ struct S {
   int x[3] = {[N] = 3};
 };
 }
+
+namespace PR28060 {
+template <class T>
+void foo(T v) {
+  struct s {
+    T *s = 0;
+  };
+}
+template void foo(int);
+}




More information about the cfe-commits mailing list