私はここにCRTPテンプレートクラスがあります。打ち鳴らすには:constexprの変数を持つことができない非リテラルタイプ
template <typename S>
class Base
{
public:
constexpr static S NOT_SET{0};
};
struct Derived : public Base<Derived>
{
};
クラン(5.0.0)がこれを受け入れない:
5 : <source>:5:24: error: constexpr variable cannot have non-literal type 'const Derived'
constexpr static S NOT_SET{0};
^
8 : <source>:8:25: note: in instantiation of template class 'Base<Derived>' requested here
struct Derived : public Base<Derived>
^
5 : <source>:5:24: note: incomplete type 'const Derived' is not a literal type
constexpr static S NOT_SET{0};
^
8 : <source>:8:8: note: definition of 'Derived' is not complete until the closing '}'
struct Derived : public Base<Derived>
^
1 error generated.
Compiler exited with result code 1
しかし、 gcc(4.9.2と6.2でテスト済み)はうまくいきます。
clangでこれを行うにはどうすればいいですか?
ありがとう:しかし、GCCのこの「機能」を利用している既存のコードベースを移植したい場合、あなたのアドバイスは何ですか? – Anton
派生した型がconstexprで構成可能である限り、(それが何であれ)_not set_バージョンを返す基本クラスにconstexpr関数を定義できます。それはあなたのために働くことができますか? – skypjack
はい、いい考えです。ありがとうございました。私はあなたの答えを受け入れるだろうが、あなたは後世のために答えにあなたのコメントを入れることができると思いますか? :-) – Anton