From fb9e5477faacb94cd5665ab3f2e334451308b0d8 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 3 Feb 2014 20:09:56 +0000 Subject: [PATCH] PR17846, PR17848: don't build a VarTemplateSpecializationDecl for a use of a variable template until we know what the template arguments actually are. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200714 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplate.cpp | 11 +++--- .../SemaTemplate/instantiate-var-template.cpp | 36 +++++++++++++++++++ 2 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 test/SemaTemplate/instantiate-var-template.cpp diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index bc66fdedb6..a6a3535d68 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -2777,10 +2777,13 @@ ExprResult Sema::BuildTemplateIdExpr(const CXXScopeSpec &SS, assert(!R.isAmbiguous() && "ambiguous lookup when building templateid"); // In C++1y, check variable template ids. - if (R.getAsSingle()) { - return Owned(CheckVarTemplateId(SS, R.getLookupNameInfo(), - R.getAsSingle(), - TemplateKWLoc, TemplateArgs)); + bool InstantiationDependent; + if (R.getAsSingle() && + !TemplateSpecializationType::anyDependentTemplateArguments( + *TemplateArgs, InstantiationDependent)) { + return CheckVarTemplateId(SS, R.getLookupNameInfo(), + R.getAsSingle(), + TemplateKWLoc, TemplateArgs); } // We don't want lookup warnings at this point. diff --git a/test/SemaTemplate/instantiate-var-template.cpp b/test/SemaTemplate/instantiate-var-template.cpp new file mode 100644 index 0000000000..bd7c43334f --- /dev/null +++ b/test/SemaTemplate/instantiate-var-template.cpp @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -verify -std=c++1y %s + +namespace PR17846 { + template constexpr T pi = T(3.14); + template constexpr T tau = 2 * pi; + constexpr double tau_double = tau; + static_assert(tau_double == 6.28, ""); +} + +namespace PR17848 { + template constexpr T var = 12345; + template constexpr T f() { return var; } + constexpr int k = f(); + static_assert(k == 12345, ""); +} + +namespace NonDependent { + template constexpr T a = 0; + template constexpr T b = a; + static_assert(b == 0, ""); +} + +namespace InstantiationDependent { + int f(int); + void f(char); + + template constexpr int a = 1; + template constexpr T b = a; // expected-error {{invalid application of 'sizeof' to an incomplete type 'void'}} + + static_assert(b == 1, ""); + static_assert(b == 1, ""); // expected-note {{in instantiation of}} expected-error {{not an integral constant}} + + template void f() { + static_assert(a == 0, ""); // expected-error {{static_assert failed}} + } +} -- 2.40.0