Bug in Compiler? Constexpr doesn't have constant value

Bug in Compiler? Constexpr doesn't have constant value


I just came across a rather weird behaviour of the Intel C++ Composer XE2013, SP1 on Windows. I managed to reduce it to the following simple test program:

template<int A>
constexpr int foo(int b) {   return A==b ? A : 0; }

template<int A> std::array<int,foo<1>(A)> bar() {  
 std::cout << "hello" << std::endl;

int main() {

When I want to compile this on windows I get the following error message: "error : function call must have a constant value in a constant expression". However I believe that the code is correct, at least I was able to compile it on linux with clang 3.3 and g++ 4.8.1 without any problems.

Is my code actually c++11 conform or is it a bug in the Intel compiler?

For completeness I have attached the above source code to this message...

Thanks in advance,


Downloadtext/x-c++src intelconstexprtest.cpp332 bytes
2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Yes indeed this does appear to be a bug in our compiler in non GNU compatibility modes.

I have entered this into our internal bug tracking database as DPD200248495. Thanks for bringing it to our attention.


Leave a Comment

Please sign in to add a comment. Not a member? Join today