要約:g ++では正常にコンパイルされるが、clangではコンパイルされないコードスニペットがあります。
詳細:
g ++で正常にコンパイルされるプロジェクトがありますが、clangでコンパイルすると、に関するエラーが発生しますerror: use of non-static data member
。問題を示す小さなテストケースを作成しようとしましたが、小さなテストケースではg++でclangと同じエラーが発生しました。
問題を示す236行のファイルをpastebinに投稿しました:http: //pastebin.com/DGnfxmYe
g ++ 4.6.3でコンパイルすると、これは正常に機能します。しかし、clang 3.2でコンパイルすると、次のエラーメッセージが表示されます。
myhashmap.hpp:169:29: error: use of non-static data member 'num_bins' of 'MyHashMap' from nested type 'iterator'
for (_index++; (_index < num_bins) && (bins[_index] == NULL); _index++)
^~~~~~~~
myhashmap.hpp:169:43: error: use of non-static data member 'bins' of 'MyHashMap' from nested type 'iterator'
for (_index++; (_index < num_bins) && (bins[_index] == NULL); _index++)
^~~~
myhashmap.hpp:171:17: error: use of non-static data member 'num_bins' of 'MyHashMap' from nested type 'iterator'
if (_index < num_bins) {
^~~~~~~~
myhashmap.hpp:172:17: error: use of non-static data member 'bins' of 'MyHashMap' from nested type 'iterator'
_theNode = bins[_index];
^~~~
コードを見ると、clangがこれらのエラーメッセージを表示している理由がわかります。私が理解していないのは、g++が最初にコードを正しくコンパイルした理由です。私はこのコードを書きませんでしたが、clangできれいにコンパイルできるようにしたいと思います。だから私はそれが何をしているのかを正確に理解しようとしています。そして、なぜそれがg ++でコンパイルされるのに、clangではコンパイルされないのかを理解することに興味があります。g++はc++標準を異なる方法で解釈しますか、それともコードが利用しているg ++拡張機能がありますか?