I stumbled upon the code which I do not understand. Here's a simplified version of it:
template <int> struct A {};
int const i = { 42 };
typedef A<i> Ai;
int const j = 42;
typedef A<j> Aj;
This code compiles with GCC in C++98 mode, but not in Clang. Clang produces the following error:
$ clang -Wall -Wextra -std=c++98 -c test.cpp
test.cpp:4:11: error: non-type template argument of type 'int' is not an integral constant expression
typedef A<i> Ai;
^
test.cpp:4:11: note: initializer of 'i' is not a constant expression
test.cpp:3:11: note: declared here
int const i = { 42 };
^
As far as I understand initialization of int
with and without curly braces should be equivalent. Clang initializes i
correctly to 42
, just doesn't think it's a compile time constant.
This code compiles well in C++11 mode.
Is there a reason j
is treated as a compile time constant and i
is not? Or is it simply a bug in Clang?
Update: I opened a ticket in LLVM bug tracker with this issue.