Author: majnemer Date: Fri Feb 21 18:17:46 2014 New Revision: 201913 URL: http://llvm.org/viewvc/llvm-project?rev=201913&view=rev Log: 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 Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=201913&r1=201912&r2=201913&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri Feb 21 18:17:46 2014 @@ -1187,14 +1187,11 @@ Decl *TemplateDeclInstantiator::VisitCXX // 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; } Modified: cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp?rev=201913&r1=201912&r2=201913&view=diff ============================================================================== --- cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp (original) +++ cfe/trunk/test/SemaTemplate/instantiate-local-class.cpp Fri Feb 21 18:17:46 2014 @@ -1,5 +1,4 @@ // RUN: %clang_cc1 -verify -std=c++11 %s -// expected-no-diagnostics template<typename T> void f0() { struct X; @@ -181,3 +180,17 @@ namespace PR14373 { return 0; } } + +namespace PR18907 { +template <typename> +class C : public C<int> {}; // expected-error{{within its own definition}} + +template <typename X> +void F() { + struct A : C<X> {}; +} + +struct B { + void f() { F<int>(); } +}; +} _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
