http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58063
Daniel Krügler <daniel.kruegler at googlemail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |daniel.kruegler@googlemail. | |com --- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> --- The behavior looks indeed odd to me (and I can confirm it for gcc 4.9 as well). I suspect at the moment that it is somehow related to the very specific definition of std::cout, because when I try to mimic the problem for a model type like the following, I cannot produce this effect: //--------------------------------------------- #include <iostream> struct my_ostream { my_ostream(){} virtual ~my_ostream() {} operator void*() const { return const_cast<my_ostream*>(this); } bool operator!() const { return false; } private: my_ostream(const my_ostream&); my_ostream& operator=(const my_ostream&); } my_cout; my_ostream& operator<<(my_ostream& os, const char* s) { std::cout << s; return os; } void f(bool x = !(std::cout << "hi!\n")) { std::cout << x << '\n'; } void f2(bool x = !(my_cout << "hi!\n")) { std::cout << x << '\n'; } int main() { f(); std::cout << "------------------\n"; f2(); } //--------------------------------------------- gives the output: <quote> hi! hi! 0 ------------------ hi! 0 </quote> Looking at the generate assembly (mingw 64 but), I see the following relevant lines: 0x004017AD lea 0x7a86d(%rip),%rdx # 0x47c021 <std::piecewise_construct+1> 0x004017B4 mov 0x7e4a5(%rip),%rcx # 0x47fc60 <.refptr._ZSt4cout> 0x004017BB callq 0x4624c0 <std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)> 0x004017C0 mov %rax,%rbx 0x004017C3 lea 0x7a857(%rip),%rdx # 0x47c021 <std::piecewise_construct+1> 0x004017CA mov 0x7e48f(%rip),%rcx # 0x47fc60 <.refptr._ZSt4cout> 0x004017D1 callq 0x4624c0 <std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)> 0x004017D6 mov (%rax),%rax 0x004017D9 sub $0x18,%rax 0x004017DD mov (%rax),%rax 0x004017E0 add %rbx,%rax 0x004017E3 mov %rax,%rcx 0x004017E6 callq 0x433f60 <std::basic_ios<char, std::char_traits<char> >::operator!() const> 0x004017EB movzbl %al,%eax 0x004017EE mov %eax,%ecx