From c5d060f4fad38c242f579e42a0f596702b0ccfbd Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sun, 16 Mar 2014 01:00:40 +0000 Subject: [PATCH] PR19152: If a variable template's type involves 'auto', instantiate the initializer with the variable in order to determine the type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204015 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateInstantiateDecl.cpp | 7 +++++-- test/SemaCXX/cxx1y-variable-templates_top_level.cpp | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 5ea21ff14a..8cfc4149e0 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3640,8 +3640,11 @@ void Sema::BuildVariableInstantiation( Context.setStaticLocalNumber(NewVar, Context.getStaticLocalNumber(OldVar)); // Delay instantiation of the initializer for variable templates until a - // definition of the variable is needed. - if (!isa(NewVar) && !InstantiatingVarTemplate) + // definition of the variable is needed. We need it right away if the type + // contains 'auto'. + if ((!isa(NewVar) && + !InstantiatingVarTemplate) || + NewVar->getType()->isUndeducedType()) InstantiateVariableInitializer(NewVar, OldVar, TemplateArgs); // Diagnose unused local variables with dependent types, where the diagnostic diff --git a/test/SemaCXX/cxx1y-variable-templates_top_level.cpp b/test/SemaCXX/cxx1y-variable-templates_top_level.cpp index 526bef0078..37d5bf3a00 100644 --- a/test/SemaCXX/cxx1y-variable-templates_top_level.cpp +++ b/test/SemaCXX/cxx1y-variable-templates_top_level.cpp @@ -441,3 +441,10 @@ namespace PR18530 { template int a; int a; // expected-error {{requires 'template<>'}} } + +namespace PR19152 { +#ifndef PRECXX11 + template const auto x = 1; + static_assert(x == 1, ""); +#endif +} -- 2.40.0