LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 17846 - constexpr variable template does not compile without non-templated constexpr variable
Summary: constexpr variable template does not compile without non-templated constexpr ...
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: C++14 (show other bugs)
Version: trunk
Hardware: All All
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-08 11:28 PST by jonathan.sauer
Modified: 2014-02-03 14:10 PST (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jonathan.sauer 2013-11-08 11:28:18 PST
The following program does not compile with clang r193986:

template <typename T>
constexpr T PI = T(3.14);

template <typename T>
constexpr T TAU = 2 * PI<T>;

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


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


This results in:

 ~/LLVM/build/Release+Asserts/bin/clang -c -std=c++1y clang.cpp   
clang.cpp:5:23: error: constexpr variable 'TAU<double>' must be initialized by a constant expression
constexpr T TAU = 2 * PI<T>;
                  ~~~~^~
clang.cpp:13:12: note: in instantiation of variable template specialization 'TAU<double>' requested here
    return TAU<double> * 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.
Comment 1 Richard Smith 2014-02-03 14:10:17 PST
Fixed by r200714.