【发布时间】:2014-09-30 15:26:35
【问题描述】:
在命名空间周围使用decltype 时,我可以编写可编译的代码,但该语句在g++4.9.1 下似乎没有任何效果,在clang 下它会产生error: unexpected namespace name 'std': expected expression
例如,以下都是在 g++ 下编译的,但程序集没有显示为它们生成的任何代码。
using s = decltype(std);
auto n = typeid(decltype(std)).name();
auto sz = n.size();
std::printf("size is %zu\n", sz+1);
std::printf("this type is: %s\n\n", n.c_str());
// the only limit is your imagination
int f();
std::ostream trash = f(typeid(decltype(std)) * 10 - 6 ^ typeid(decltype(std)));
如果 g++ 允许这样做是正确的?如果是这样,代码消失而不是导致编译时错误有什么好处?
【问题讨论】:
-
似乎是 g++ 中的一个错误。