下面是一段代码:静态constexpr方法的实现会导致gcc错误?
class Class
{
static constexpr int getBug();
};
constexpr int Class::getBug()
{
return 0;
}
我基本上做的是在声明类声明一个static
constepxr
方法,那么我实现它。
原始代码被分割为两个文件,并且包含更多已被剥离的方法/属性,只留下所需的代码。
当我编译从GCC 4.6.0代码中,我得到以下错误:
Class.cpp:6:29: internal compiler error: in merge_types, at cp/typeck.c:825
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
这真的是一个错误吗?
在这种情况下,我必须提供哪些报告?
我测试过的代码上online C++0x compiler,并出现以下错误:
prog.cpp:3:33: error: the 'constexpr' specifier cannot be used in a function declaration that is not a definition
prog.cpp:6:29: error: a constexpr function cannot be defined outside of its class
该编译器使用GCC 4.5.1。 它让我知道,我的代码是非法的形成,但引进更多的问题:
- 为什么GCC 4.5.1给出错误和GCC 4.6.0报告中的错误?
写最后一段后,我测试了回来GCC 4.6.0剥离static
关键字和独立执行编译没有任何警告!
- 为什么同一家庭循规蹈矩两个编译如此不同?
我知道constexpr
方法应避免return
不同的任何声明,这可能解释了GCC 4.5.1错误报告。 由于我的方法使用宏条件返回好(常量)值,它需要几行解释为什么我想要使用分离的实现(除了通常的建议)。
我的配置:
Mac OS X.7
GCC 4.6.0
Target: x86_64-apple-darwin10.7.0
Configured with: ./configure
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.7.0' '-v' '-save-temps' '-std=c++0x' '-c' '-shared-libgcc' '-mtune=core2'
在内部编译器错误是*总是*一个问题,因为它是编译器中的错误。看看它是否已经被报告,如果没有,就提交。 GCC中有很多与新的C++ 11功能相关的错误,所以这绝不意外。 –