]> granicus.if.org Git - clang/commitdiff
PR19152: If a variable template's type involves 'auto', instantiate the
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 16 Mar 2014 01:00:40 +0000 (01:00 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 16 Mar 2014 01:00:40 +0000 (01:00 +0000)
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
test/SemaCXX/cxx1y-variable-templates_top_level.cpp

index 5ea21ff14a2c528ac1a2cf2e39ff0d3bc118f1aa..8cfc4149e060b77afd000f45a8cd868f47179ba0 100644 (file)
@@ -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
index 526bef007873813ec4db100aada611390f3d5c1d..37d5bf3a0055eab3eed2ab5e74b33bdf880709f7 100644 (file)
@@ -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
+}