2017-10-18 12 views
4

自動差分ライブラリAdeptを使用しようとしていますが、gcc 4.9.0とicc 16.0.2で動作させましたが、VS 2017とClang 4.0.1エラー: 'EndIndex'に 'rank_'というメンバーがありません

私はこの問題を以下のスニペットにまで減らしました。ライブラリ作成者の問題に取り組んでいますが、知識のために、このコードが2つのコンパイラで動作し、他の2人で構築する。 VS 2017のための

template <typename A> 
struct Expression 
{ 
    static const int rank = A::rank_; 
}; 

struct EndIndex : public Expression<EndIndex> 
{ 
    static const int rank_ = 0; 
}; 

int main(int argc, char ** argv) 
{ 
    return 0; 
} 

出力は次のとおりです。クラン4.0.1用

1>------ Build started: Project: Test, Configuration: Debug Win32 ------ 
1>Source.cpp 
1>d:\Test\source.cpp(4): error C2039: 'rank_': is not a member of 'EndIndex' 
1>d:\Test\source.cpp(7): note: see declaration of 'EndIndex' 
1>d:\Test\source.cpp(8): note: see reference to class template instantiation 'Expression<EndIndex>' being compiled 
1>d:\Test\source.cpp(4): error C2065: 'rank_': undeclared identifier 
1>d:\Test\source.cpp(4): error C2131: expression did not evaluate to a constant 
1>d:\Test\source.cpp(4): note: failure was caused by non-constant arguments or reference to a non-constant symbol 
1>d:\Test\source.cpp(4): note: see usage of 'rank_' 
1>Done building project "Test.vcxproj" -- FAILED. 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

そして出力:それはだから

source.cpp:4:37: error: no member named 'rank_' in 'EndIndex' 
           static const int rank = A::rank_; 
                 ~~~^ 
source.cpp:7:38: note: in instantiation of template class 'Expression<EndIndex>' requested here 
                 struct EndIndex : public Expression<EndIndex> 
+0

は、私は別のCRTPの質問に探していた答えを見つけることが起こります。 [link](https://stackoverflow.com/questions/46576847/clang-vs-gcc-crtp-constexpr-variable-cannot-have-non-literal-type/46578880#46578880) –

答えて

3

おそらく、rank_がその段階で定義されていないために発生します。アップルLLVMのバージョン9.0.0(打ち鳴らす-900.0.38)用

次の修正を:

template <typename A> 
struct Expression 
{ 
    static const int rank; 
}; 

struct EndIndex : public Expression<EndIndex> 
{ 
    static const int rank_ = 0; 
}; 

template <typename A> 
const int Expression<A>::rank = A::rank_; 
+0

この提案は、 VS 2017. –

+0

@ManuelNúñez、それを確認してくれてありがとう! –

0

のVisual C++と打ち鳴らすには、単にEndIndexrank_メンバーを見つけることができません宣言される前にアクセスされます。このような空想的なコードは、しばしばいくつかの環境で問題を引き起こします。

関連する問題