From: Richard Smith Date: Wed, 8 Aug 2018 00:42:42 +0000 (+0000) Subject: PR38286: Don't crash when attempting to define a constructor for an X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=14dc3eba2dbbd2b777a105cafa45760940a0fe29;p=clang PR38286: Don't crash when attempting to define a constructor for an incomplete class template. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339210 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 22f13280c3..c851a81af4 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -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); diff --git a/test/SemaCXX/constructor.cpp b/test/SemaCXX/constructor.cpp index 105605c6e3..33ea496634 100644 --- a/test/SemaCXX/constructor.cpp +++ b/test/SemaCXX/constructor.cpp @@ -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 struct A; + template A::A() {} // expected-error {{incomplete type 'A' named in nested name specifier}} + /*FIXME: needed to recover properly from previous error*/; + template struct B; + template void B::f() {} // expected-error {{out-of-line definition of 'f' from class 'B'}} + template struct C; + template C::~C() {} // expected-error {{no type named 'C' in 'C'}} +}