https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64372
Harald van Dijk <harald at gigawatt dot nl> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |harald at gigawatt dot nl --- Comment #2 from Harald van Dijk <harald at gigawatt dot nl> --- (In reply to Manuel López-Ibáñez from comment #1) > Probably even: > > const char& > foz(const char* p) > { > return *p; > } > > is undefined. No, that is fine. *p is an lvalue already, so no temporary gets created. The original code was supposed to get a warning because ptr ? *ptr : throw ptr was not an lvalue: for a ? b : c to be an lvalue, both b and c needed to be lvalues. However, the C++ standard has since changed, and if one operand is a throw-expression, and the other is an lvalue, the result is now an lvalue. CWG issue 1560: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1560 So in -std=c++11 mode, there should be no temporary, and no warning. (I haven't checked if current versions of GCC already implement that, but I can find no bug reports about it.)