http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58063

            Bug ID: 58063
           Summary: default arguments evaluated twice per call
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: plokinom at gmail dot com

% cat try.cc
#include <iostream>

void f(bool x = !(std::cout << "hi!\n")) {
    std::cout << x << '\n';
}

int main() {
    f();
}

% g++ try.cc
% ./a.out 
hi!
hi!
0

My question: Why is the default argument evaluated twice for each call to f()?

Is this allowed by the standard or a bug in g++?


% g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/home/mauke/usr/local/libexec/gcc/i686-pc-linux-gnu/4.8.1/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.8.1/configure --prefix=/home/mauke/usr/local
--with-arch=native --with-tune=native --enable-__cxa_atexit
--enable-languages=c,c++,go --disable-nls
Thread model: posix
gcc version 4.8.1 (GCC)

Reply via email to