【发布时间】:2013-01-14 22:49:10
【问题描述】:
总结: 我有一个code snippet,可以用 g++ 编译,但不能用 clang。
详情:
我有一个使用 g++ 编译的项目,但是使用 clang 编译时,我收到关于 error: use of non-static data member 的错误。我尝试创建一个小测试用例来演示问题,但是对于小测试用例,g++ 给出了与 clang 相同的错误。
我已向 pastebin 发布了一个 236 行的文件来演示该问题: 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++ 扩展?
【问题讨论】: