The compiler error states that "template argument of type 'int' is not an integral constant expression"
for int const i = { 42 };
According to 98 standard the template argument should fall into this category:
14.3.2 / 1
A template-argument for a non-type, non-template template-parameter shall be one of:
- an integral constant-expression of integral or enumeration type; or
...
and the definition of integral constant expression int const i
fall into this category:
5.19 Constant expressions
An integral constant-expression can involve only literals (2.13), enumerators, const variables or static data members
and for the initialization of i
(like Mike Seymour post):
8.5 Initializers /13
If T is a scalar type, then a declaration of the form
T x = { a };
is equivalent to
T x = a;
Now based on this post the declaration of const int
and int const
should be the same (could not find this specifically in standard) making i
a const variable. So any usage of i
should be an integral constant expression regardless of the initialization method. It appears there is a bug in clang. Checking the web i could not find a bug report only two more or less similar:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=666539
and
http://lists.cs.uiuc.edu/pipermail/llvmbugs/2011-March/017353.html