From 1b029d302fa469975b82779303660c3ed35cc9b7 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Mon, 10 Aug 2015 21:54:08 +0000 Subject: [PATCH] If a variable template is inside a context with template arguments that is being instantiated, and that instantiation fails, fail our instantiation instead of crashing. Errors have already been emitted. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@244515 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateInstantiateDecl.cpp | 1 + test/SemaCXX/cxx1y-variable-templates_in_class.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 4fa54257ee..c8a067658b 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1143,6 +1143,7 @@ Decl *TemplateDeclInstantiator::VisitVarTemplateDecl(VarTemplateDecl *D) { VarDecl *VarInst = cast_or_null(VisitVarDecl(Pattern, /*InstantiatingVarTemplate=*/true)); + if (!VarInst) return nullptr; DeclContext *DC = Owner; diff --git a/test/SemaCXX/cxx1y-variable-templates_in_class.cpp b/test/SemaCXX/cxx1y-variable-templates_in_class.cpp index 123fcfff7f..65e2d6b608 100644 --- a/test/SemaCXX/cxx1y-variable-templates_in_class.cpp +++ b/test/SemaCXX/cxx1y-variable-templates_in_class.cpp @@ -327,3 +327,14 @@ struct S { static int f : I; // expected-error {{static member 'f' cannot be a bit-field}} }; } + +namespace b20896909 { + // This used to crash. + template struct helper {}; + template class A { + template static helper x; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}} + }; + void test() { + A ai; // expected-note {{in instantiation of}} + } +} -- 2.40.0