https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66146
Bug ID: 66146 Summary: call_once not C++11-compliant on ppc64le Product: gcc Version: 5.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: andrey.vul at gmail dot com Target Milestone: --- std::call_once is not C++11 (or even N2447) compliant on ppc64le. According to N2447, "If the invocation of func results in an exception being thrown, the exception is propagated to the caller and the effects are as-if this invocation of call_once did not occur." Given the code #include <mutex> int call_count = 0; void func_() { printf("Inside func_ call_count %d\n", call_count); if (++call_count < 2) throw 0; } int main() { std::once_flag flag_; printf("Before calling call_once flag_: %d\n", *(int*)&flag_); try { std::call_once(flag_, func_); } catch(...) { printf("Inside catch all excepton flag_: %d\n", *(int*)&flag_); } printf("before the 2nd call to call_once flag_: %d\n", *(int*)&flag_); std::call_once(flag_, func_); } the output on amd64 is Before calling call_once flag_: 0 Inside func_ call_count 0 Inside catch all excepton flag_: 0 before the 2nd call to call_once flag_: 0 but on ppc64el is Before calling call_once flag_: 0 Inside func_ call_count 0 Inside catch all excepton flag_: 1 before the 2nd call to call_once flag_: 1 amd64 has the correct behavior. ppc64le gcc tested: $gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/powerpc64le-linux-gnu/4.9/lto-wrapper Target: powerpc64le-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.9.1-16ubuntu6' --with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.9 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.9 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libsanitizer --disable-libquadmath --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-ppc64el/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-ppc64el --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-ppc64el --with-arch-directory=ppc64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-secureplt --with-cpu=power7 --with-tune=power8 --disable-multilib --enable-multiarch --disable-werror --with-long-double-128 --enable-checking=release --build=powerpc64le-linux-gnu --host=powerpc64le-linux-gnu --target=powerpc64le-linux-gnu Thread model: posix gcc version 4.9.1 (Ubuntu 4.9.1-16ubuntu6) $gcc-5.1 -v Using built-in specs. COLLECT_GCC=/home/andreyv/nfs/gcc/bin/gcc-5.1 COLLECT_LTO_WRAPPER=/nfs/home/andreyv/gcc/bin/../libexec/gcc/powerpc64le-unknown-linux-gnu/5.1.0/lto-wrapper Target: powerpc64le-unknown-linux-gnu Configured with: ../gcc-5.1.0/configure --prefix=/nfs/home/andreyv/gcc/ --program-suffix=-5.1 --enable-languages=c,c++,lto CFLAGS='-O2 -mtune=native' CXXFLAGS='-O2 -mtune=native' Thread model: posix gcc version 5.1.0 (GCC) Both versions compiled and run on Ubuntu 14.10 on a Power8. gcc-5.1 invocation: $ ~/nfshome/gcc/bin/g++-5.1 -std=c++11 -lpthread -Wl,-rpath=~/nfshome/gcc/lib64 -Wall -Wextra a.cc gcc-4.9 invocation: g++ -std=c++11 -lpthread -Wall -Wextra a.cc