2016-03-01 131 views
2

当编译此代码铛(3.0-6ubuntu3版):无法初始化constexpr

constexpr int foo(const int n) { 
    return n + 1; 
} 

int main(void) { 
    constexpr int x = 5 * 4 + 12 + 8; 
    constexpr int y = foo(x); 
    return 0; 
} 

使用这个命令:

clang -std=c++11 -c constexprExample.cpp 

我获得以下错误:

error: constexpr variable 'y' must be initialized by a constant expression

代码或编译器有问题吗?

+0

尝试将y定义为常量而不是常量表达式.... – asalic

回答

5

这是在3.1中修复的叮当声3.0中的一个错误。