私はGCC 4.8で正常にコンパイルしているようだ打ち鳴らす3.3でいくつかのコードをコンパイルしています:打ち鳴らす3.3とconstexprの制約
オリジナルのコードだった:打ち鳴らすには
template <std::size_t N> struct helper { typedef void type; };
template <> struct helper<64> { typedef int64_t type; };
template <> struct helper<32> { typedef int32_t type; };
template <> struct helper<16> { typedef int16_t type; };
template <> struct helper<8> { typedef int8_t type; };
template <std::size_t I, std::size_t F>
struct test
{
typedef typename helper<I+F>::type value_type;
static constexpr std::size_t frac_mask = ~((~value_type(0)) << F);
};
、私は宣言しようとすると、私がコードを変換する場合、それで遊んで
test.cpp:41:34: error: constexpr variable 'frac_mask' must be initialized by a constant expression
static constexpr std::size_t frac_mask = ~((~value_type(0)) << F);
:テスト< 16,16>またはテスト< 8,0>は、私はエラーを取得する
template <std::size_t I, std::size_t F>
struct test
{
typedef typename helper<I+F>::type value_type;
typedef typename std::make_unsigned<value_type>::type mask_type;
static constexpr mask_type frac_mask = ~((~mask_type(0)) << F);
};
それはほとんどの場合(I、Fの値)でコンパイルが、私はテスト< 8、0>を宣言した場合、私はエラーを取得する:
test.cpp:23:36: error: constexpr variable 'frac_mask' must be initialized by a constant expression
test.cpp:66:15: note: in instantiation of template class 'test<8, 0>' requested here
test.cpp:23:66: note: left shift of negative value -1
static constexpr mask_type frac_mask = ~((~mask_type(0)) << F);
私の質問は - いくつかのルールがあります私はconstexprの仕様の点でここに違反していますか?また、最後のエラー - マスク型はunsignedです - これは私が負の値をシフトしていると思うか、コードを誤読していると思うコンパイラの問題ですか?
[テンプレートのデフォルト引数でconstexprを呼び出す]の複製が可能です(http://stackoverflow.com/questions/10721130/calling-constexpr-in-default-template-argument) –
uint8_tをintに変換するタイプのプロモーションルール。署名されていますか? –