Hi rsmith, hfinkel,

Fix for clang crash when instantiating a template with qualified lookup for 
members in non-class types

http://reviews.llvm.org/D5769

Files:
  lib/Sema/SemaCXXScopeSpec.cpp
  lib/Sema/SemaExprMember.cpp
  test/SemaTemplate/instantiate-non-dependent-types.cpp
Index: test/SemaTemplate/instantiate-non-dependent-types.cpp
===================================================================
--- test/SemaTemplate/instantiate-non-dependent-types.cpp
+++ test/SemaTemplate/instantiate-non-dependent-types.cpp
@@ -11,4 +11,34 @@
   typedef instantiate<&X1<int>::member> i; // expected-note{{in instantiation of}}
 };
 
-X2<int> x; 
+X2<int> x;
+
+template <class T, class A> class C {
+public:
+  int i;
+  void f(T &t) {
+    T *q = new T();
+    t.T::~T();
+    q->~T();
+    // expected-error@+1 {{'int' is not a class, namespace, or scoped enumeration}}
+    q->A::~A();
+    // expected-error@+1 {{no member named '~int' in 'Q'}}
+    q->~A();
+
+    delete q;
+  }
+};
+
+class Q {
+public:
+  Q() {}
+  ~Q() {}
+};
+
+C<Q, int> dummy;
+int main() {
+  Q qinst;
+  // expected-note@+1 {{in instantiation of member function 'C<Q, int>::f' requested here}}
+  dummy.f(qinst);
+}
+
Index: lib/Sema/SemaExprMember.cpp
===================================================================
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -596,7 +596,12 @@
   if (SS.isSet()) {
     // If the member name was a qualified-id, look into the
     // nested-name-specifier.
-    DC = SemaRef.computeDeclContext(SS, false);
+    if ((DC = SemaRef.computeDeclContext(SS, false)) == nullptr) {
+      SemaRef.Diag(SS.getBeginLoc(), diag::err_expected_class_or_namespace)
+          << QualType(SS.getScopeRep()->getAsType(), /*Quals*/ 0)
+          << SemaRef.getLangOpts().CPlusPlus;
+      return true;
+    }
 
     if (SemaRef.RequireCompleteDeclContext(SS, DC)) {
       SemaRef.Diag(SS.getRange().getEnd(), diag::err_typecheck_incomplete_tag)
Index: lib/Sema/SemaCXXScopeSpec.cpp
===================================================================
--- lib/Sema/SemaCXXScopeSpec.cpp
+++ lib/Sema/SemaCXXScopeSpec.cpp
@@ -141,9 +141,9 @@
 
   case NestedNameSpecifier::TypeSpec:
   case NestedNameSpecifier::TypeSpecWithTemplate: {
-    const TagType *Tag = NNS->getAsType()->getAs<TagType>();
-    assert(Tag && "Non-tag type in nested-name-specifier");
-    return Tag->getDecl();
+    if (const TagType *Tag = NNS->getAsType()->getAs<TagType>())
+      return Tag->getDecl();
+    return nullptr;
   }
 
   case NestedNameSpecifier::Global:
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to