Dan*_*rey 6 c++ clang libstdc++ c++11
我很遗憾为什么Clang拒绝以下代码:
#include <typeinfo>
#include <exception>
const char* get_name( const std::exception_ptr eptr )
{
return eptr.__cxa_exception_type()->name();
}
int main() {}
Run Code Online (Sandbox Code Playgroud)
GCC没问题,但Clang抱怨说它type_info是一个不完整的类型:
$ g++-4.7 -std=c++0x -O3 -Wall -Wextra t.cc -o t
$ clang++-3.2 -std=c++0x -O3 -Wall -Wextra t.cc -o t
t.cc:6:37: error: member access into incomplete type 'const class type_info'
return eptr.__cxa_exception_type()->name();
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/exception_ptr.h:144:19: note: forward declaration of
'std::__exception_ptr::type_info'
const class type_info*
^
1 error generated.
$
Run Code Online (Sandbox Code Playgroud)
问题:如何使用Clang修复它?或者我错过了什么,Clang拒绝代码是对的吗?
感谢@HowardHinnant的评论,我设法解决了这个问题。这个问题在预处理器输出变得明显:++的libstdc包括<exception>从<type_info>它甚至之前宣布 std::type_info。这使Clang有了新的前向声明std::__exception_ptr::type_info。解决方案非常简单,因为它是非法的:
namespace std { class type_info; }
#include <typeinfo>
#include <exception>
const char* get_name( const std::exception_ptr eptr )
{
return eptr.__cxa_exception_type()->name();
}
int main() {}
Run Code Online (Sandbox Code Playgroud)
好像我应该检查libstdc ++是否已经有一个错误报告,如果没有,请创建一个。
更新:错误#56468现在已修复GCC 4.7.3+
| 归档时间: |
|
| 查看次数: |
2543 次 |
| 最近记录: |