Here is a piece of code:
class Class
{
static constexpr int getBug();
};
constexpr int Class::getBug()
{
return 0;
}
What I basically do is declaring a static
constepxr
method in class declaration, then I implement it.
The original code was split in two file, and contained more methods / attributes which have been stripped, leaving only the required code.
When I compile the code I get the following error from 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.
Is this really a bug?
In that case, what must I provide my report with?
I've tested the code on an online C++0x compiler and get the following error:
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
This compiler uses GCC 4.5.1. It let me know that my code is ill-formed, but introduce more question:
- Why does GCC 4.5.1 give an error and GCC 4.6.0 report a bug?
After writing the last paragraph, I tested back on GCC 4.6.0 stripping the static
keyword and the separate implementation compiles without any warning!
- Why do two compiler of the same family behave so differently?
I know that constexpr
methods should avoid any statement different to return
, which may explain the GCC 4.5.1 error reporting.
As my method uses macro condition to return the good (constant) value, it takes a couple of line which explains why I want to use separated implementation (in addition to the usual recommendation).
My configuration:
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'