当在命名空间周围使用 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++允许这样做,那么它的优点是什么?与其导致编译时错误相比,代码消失有何优势?