Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constexpr variable template does not compile without non-templated constexpr variable #18220

Closed
llvmbot opened this issue Nov 8, 2013 · 1 comment
Labels
bugzilla Issues migrated from bugzilla c++14

Comments

@llvmbot
Copy link
Member

llvmbot commented Nov 8, 2013

Bugzilla Link 17846
Resolution FIXED
Resolved on Feb 03, 2014 14:10
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @zygoloid

Extended Description

The following program does not compile with clang r193986:

template
constexpr T PI = T(3.14);

template
constexpr T TAU = 2 * PI;

// A: Without this line using TAU below results in a compile error
//constexpr double HALF_PI = PI / 2;

int main(int argc, char**)
{
return TAU * argc;
}

This results in:

/LLVM/build/Release+Asserts/bin/clang -c -std=c++1y clang.cpp
clang.cpp:5:23: error: constexpr variable 'TAU' must be initialized by a constant expression
constexpr T TAU = 2 * PI;
~~~~^

clang.cpp:13:12: note: in instantiation of variable template specialization 'TAU' requested here
return TAU * argc;
^
1 error generated.

After uncommenting the line below "A", the code compiles successfully.

It seems that a constexpr variable template cannot be used in the definition of another constexpr variable template when it is not used in the definition of a non-template constexpr variable as well.

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Feb 3, 2014

Fixed by r200714.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++14
Projects
None yet
Development

No branches or pull requests

1 participant