下面是一段代碼:靜態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功能相關的錯誤,所以這絕不意外。 –