]> granicus.if.org Git - clang/commitdiff
PR38286: Don't crash when attempting to define a constructor for an
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 8 Aug 2018 00:42:42 +0000 (00:42 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 8 Aug 2018 00:42:42 +0000 (00:42 +0000)
incomplete class template.

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

lib/Sema/SemaExprCXX.cpp
test/SemaCXX/constructor.cpp

index 22f13280c382d20c95df9af805250b572a61c783..c851a81af46450245127e02c6c88ec8cc014dfc6 100644 (file)
@@ -113,9 +113,15 @@ ParsedType Sema::getConstructorName(IdentifierInfo &II,
       break;
     }
   }
-  if (!InjectedClassName && CurClass->isInvalidDecl())
+  if (!InjectedClassName) {
+    if (!CurClass->isInvalidDecl()) {
+      // FIXME: RequireCompleteDeclContext doesn't check dependent contexts
+      // properly. Work around it here for now.
+      Diag(SS.getLastQualifierNameLoc(),
+           diag::err_incomplete_nested_name_spec) << CurClass << SS.getRange();
+    }
     return ParsedType();
-  assert(InjectedClassName && "couldn't find injected class name");
+  }
 
   QualType T = Context.getTypeDeclType(InjectedClassName);
   DiagnoseUseOfDecl(InjectedClassName, NameLoc);
index 105605c6e37b44ee4f2ef5adf0ce17892e50b7a7..33ea4966349191869305619abbc8724673de9a8e 100644 (file)
@@ -86,3 +86,14 @@ A::S::operator int() { return 1; }
 
 A::S::~S() {}
 
+namespace PR38286 {
+  // FIXME: It'd be nice to give more consistent diagnostics for these cases
+  // (but they're all failing for somewhat different reasons...).
+  template<typename> struct A;
+  template<typename T> A<T>::A() {} // expected-error {{incomplete type 'A' named in nested name specifier}}
+  /*FIXME: needed to recover properly from previous error*/;
+  template<typename> struct B;
+  template<typename T> void B<T>::f() {} // expected-error {{out-of-line definition of 'f' from class 'B<type-parameter-0-0>'}}
+  template<typename> struct C;
+  template<typename T> C<T>::~C() {} // expected-error {{no type named 'C' in 'C<type-parameter-0-0>'}}
+}