次のC++0xコードをコンパイルしようとすると、エラーが発生します。
template<int n> struct foo { };
struct bar {
static constexpr int number() { return 256; }
void function(foo<number()> &);
};
gcc 4.6.1では、エラーメッセージは次のとおりです。
test.cc:6:27: error: ‘static constexpr int bar::number()’ used before its definition
test.cc:6:28: note: in template argument for type ‘int’
clang 2.8では、エラーメッセージは次のとおりです。
test.cc:6:20: error: non-type template argument of type 'int' is not an integral
constant expression
void function(foo<number()> &);
^~~~~~~~
1 error generated.
関数を基本クラスに移動するconstexprと、gccで機能し、clangで同じエラーメッセージが表示されます。
template<int n> struct foo { };
struct base {
static constexpr int number() { return 256; }
};
struct bar : base {
void function(foo<number()> &);
};
コードは間違っていますか、それともgcc4.6のC++ 0xの実装の制限またはバグですか?コードが間違っている場合、なぜそれが間違っているのですか、そしてC ++ 11標準のどの節がそれが間違っていると言っていますか?