https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65201
Mikhail Maltsev <maltsevm at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |maltsevm at gmail dot com --- Comment #2 from Mikhail Maltsev <maltsevm at gmail dot com> --- Reduced testcase, miscompilation, works on clang 3.5.0, but causes segfault on trunk (r221132) and on g++ 4.8.2 20140120, x86_64-unknown-linux-gnu: $ cat ./range-for30_r2.cc struct str { str () : v(0) {} str (const str &s) : v(s.v) {} ~str () { v = 0; } int v; }; str data[1]; struct vec { str *begin () { return data; } str *end () { return data + 1; } }; vec split (str &s) { s = str(); return vec(); } int main () { str foo; for (str &foo : split(foo)) foo = str(); return foo.v; } And here is an even more minimized testcase (technically it's a different kind of bug, "accepts invalid") - but I suppose that these bugs are related. $ cat ./range-for30_r.cc struct str { }; struct vec { str *begin () {} str *end () {} }; vec split (str) {} int main () { for (str foo : split(foo)) ; } Clang rejects this with the following error: ./range-for30_r.cc:8:24: error: use of undeclared identifier 'foo'; did you mean 'for'? for (str foo : split(foo))