diff options
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 7 | ||||
-rw-r--r-- | clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp | 7 |
2 files changed, 12 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 5ea21ff14a2..8cfc4149e06 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/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<VarTemplateSpecializationDecl>(NewVar) && !InstantiatingVarTemplate) + // definition of the variable is needed. We need it right away if the type + // contains 'auto'. + if ((!isa<VarTemplateSpecializationDecl>(NewVar) && + !InstantiatingVarTemplate) || + NewVar->getType()->isUndeducedType()) InstantiateVariableInitializer(NewVar, OldVar, TemplateArgs); // Diagnose unused local variables with dependent types, where the diagnostic diff --git a/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp b/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp index 526bef00787..37d5bf3a005 100644 --- a/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp +++ b/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp @@ -441,3 +441,10 @@ namespace PR18530 { template<typename T> int a; int a<int>; // expected-error {{requires 'template<>'}} } + +namespace PR19152 { +#ifndef PRECXX11 + template<typename T> const auto x = 1; + static_assert(x<int> == 1, ""); +#endif +} |