【发布时间】:2017-10-18 08:05:55
【问题描述】:
一位同事不小心写了这样的代码:
struct foo {
foo() : baz(foobar) {}
enum bar {foobar, fbar, foob};
bar baz;
};
void f() {
for( auto x : { foo::foobar,
foo::fbar,
foo::
foo::
foo::foob } );
// ...
}
GCC 5.1.0 编译这个。
编译的规则是什么?
【问题讨论】:
-
您能否更具体地说明您不希望编译干净的部分?
-
缺少包含文件,for 循环缺少语句,但除此之外它还能编译
-
这个可以简化为
struct foo { static const int v{42}; }; auto x{foo::foo::foo::foo::foo::v}; -
@sbi 哪一部分让你感到困惑?注入的类名?基于范围的 for 循环?
标签: c++ c++11 gcc language-lawyer names