次のコードは、g++ 4.8.2 とのリンクに失敗します。
#include <map>
struct Foo
{
constexpr static int foo = 1;
};
static std::map<int, int> map {{1, Foo::foo}};
int main()
{
return Foo::foo;
}
次のエラーが表示されます。
g++ -std=c++11 -o foo foo.cc
/tmp/ccZXCwiK.o: In function `__static_initialization_and_destruction_0(int, int)':
foo.cc:(.text+0x51): undefined reference to `Foo::foo'
マップをコメントアウトすると、問題なくリンクします。これはコンパイラのバグですか、それとも標準に欠けている特殊なケースですか?