From fb9b689230eed1d9c1b7cecc80e4545d233b3b91 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Sat, 22 Feb 2014 00:17:46 +0000 Subject: [PATCH] Sema: Don't crash when trying to instantiate a local class with an invalid base specifier It was previously thought that Sema::InstantiateClass could not fail from within this point in instantiate. However, it can happen if the class is invalid some way (i.e. invalid base specifier). This fixes PR18907. Differential Revision: http://llvm-reviews.chandlerc.com/D2850 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201913 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateInstantiateDecl.cpp | 13 +++++-------- test/SemaTemplate/instantiate-local-class.cpp | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 7b84a06eaa..6439b9208c 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1187,14 +1187,11 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) { // DR1484 clarifies that the members of a local class are instantiated as part // of the instantiation of their enclosing entity. if (D->isCompleteDefinition() && D->isLocalClass()) { - if (SemaRef.InstantiateClass(D->getLocation(), Record, D, TemplateArgs, - TSK_ImplicitInstantiation, - /*Complain=*/true)) { - llvm_unreachable("InstantiateClass shouldn't fail here!"); - } else { - SemaRef.InstantiateClassMembers(D->getLocation(), Record, TemplateArgs, - TSK_ImplicitInstantiation); - } + SemaRef.InstantiateClass(D->getLocation(), Record, D, TemplateArgs, + TSK_ImplicitInstantiation, + /*Complain=*/true); + SemaRef.InstantiateClassMembers(D->getLocation(), Record, TemplateArgs, + TSK_ImplicitInstantiation); } return Record; } diff --git a/test/SemaTemplate/instantiate-local-class.cpp b/test/SemaTemplate/instantiate-local-class.cpp index 2bf24c2188..c9897b9c61 100644 --- a/test/SemaTemplate/instantiate-local-class.cpp +++ b/test/SemaTemplate/instantiate-local-class.cpp @@ -1,5 +1,4 @@ // RUN: %clang_cc1 -verify -std=c++11 %s -// expected-no-diagnostics template void f0() { struct X; @@ -181,3 +180,17 @@ namespace PR14373 { return 0; } } + +namespace PR18907 { +template +class C : public C {}; // expected-error{{within its own definition}} + +template +void F() { + struct A : C {}; +} + +struct B { + void f() { F(); } +}; +} -- 2.40.0