https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69191
Bug ID: 69191 Summary: Wrong equality comparison between error_code and error_condition + segfault Product: gcc Version: 4.9.3 Status: UNCONFIRMED Severity: critical Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: eyenseo at gmail dot com Target Milestone: --- Created attachment 37264 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37264&action=edit Precompiled minimal testcase Greetings! This is a bug (maybe two) regarding the comparison of std::error_condition and std::error_code. An error_code and an error_condition with same value, message and category name are not identified as same - but they should. While pinpointing this bug I happened to produce a segmentation fault in libstdc++ that is most probably part of the comparison bug. Using Clang with libstdc++ produces the same result (including segfault). Using Clang with libc++ produces the expected results and there is no segfault. command line: g++ --std=c++11 main.cpp && ./a.out output: code == con1: 0 code == con2: 1 con1 == con2: 0 con1 == con3: 0 con2 == con3: 0 code: value: 13 message: Permission denied category name: generic con1: value: 13 message: Permission denied category name: generic con2: value: 13 message: Permission denied category name: generic con3: value: 0 message: Success category name: generic expected: code == con1: 1 code == con2: 1 con1 == con2: 1 con1 == con3: 1 con2 == con3: 1 code: value: 13 message: Permission denied category name: generic con1: value: 13 message: Permission denied category name: generic con2: value: 13 message: Permission denied category name: generic con3: value: 13 message: Permission denied category name: generic Source: main.cpp #include <system_error> #include <iostream> #define equals(a, b) std::cout << #a " == " #b ": " << (a == b) << '\n'; #define print(a) \ std::cout << #a ":\tvalue: " << a.value() << "\n\tmessage: " << a.message() \ << "\n\tcategory name: " << a.category().name() << '\n'; int main(int, char const* []) { auto code = std::make_error_code(std::errc::permission_denied); auto con1 = std::make_error_condition(std::errc::permission_denied); auto con2 = code.category().default_error_condition(code.value()); auto con3 = code.default_error_condition(); equals(code, con1); // This should be true equals(code, con2); // This is true // equals(code, con3); // Segmentation fault // // std::_V2::error_category::equivalent(int, // // std::error_condition const&) const () from // // /usr/lib/x86_64-linux-gnu/libstdc++.so.6 equals(con1, con2); // This should be true equals(con1, con3); // This should be true equals(con2, con3); // This should be true std::cout << '\n'; print(code); // Same as con1 and con2 print(con1); // Same as code and con2 print(con2); // Same as code and con1 print(con3); // This should be the same as code and con1 and con2 return 0; } My system is: x86_64-linux-gnu GCC build: Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.9.3-8ubuntu2~14.04' --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-vtable-verify --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-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu