]> granicus.if.org Git - clang/commitdiff
[Sema] Don't crash when a field w/ a mem-initializer clashes with a record name
authorDavid Majnemer <david.majnemer@gmail.com>
Thu, 9 Jun 2016 05:26:56 +0000 (05:26 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Thu, 9 Jun 2016 05:26:56 +0000 (05:26 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272247 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiate.cpp
test/SemaCXX/member-init.cpp

index 554d1abbed165c0dea90effa422f142af7a0fe7b..24a47d19421dfcd896c03e94c800c55241889e9c 100644 (file)
@@ -2637,8 +2637,7 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation,
             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);
       }
index b3ee30b456ec1f933c164cce1862e49e154d23af..65c8873117ab57e07f148d0d67808e1a597d73c6 100644 (file)
@@ -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);
+}