Description of problem: When attempting to rebuild the gtest-1.7.0 package in Fedora 25, we discovered the build was failing due to self-test failures. Further investigation revealed that the package build and self-tests would succeed if the default C++ optimization flag (-O2) was removed. It was found that executables compiled with C++ optimization would segfault instead of properly handling exceptions. Version-Release number of selected component (if applicable): gcc-c++-6.2.1-2.fc25.x86_64 How reproducible: Every time Steps to Reproduce: 1. sudo dnf install gcc-c++ cmake 2. mkdir workspace 3. cd workspace 4. wget https://github.com/google/googletest/archive/release-1.7.0/gtest-1.7.0.zip 5. unzip gtest-1.7.0.zip 6. GTEST_DIR=$(pwd)/googletest-release-1.7.0 7. mkdir build-unopt 8. pushd build-unopt 9. cmake -Dgtest_build_tests=ON ${GTEST_DIR} 10. VERBOSE=1 make CXX_FLAGS= gtest_catch_exceptions_ex_test_ gtest_catch_exceptions_no_ex_test_ 11. ctest -R gtest_catch_exceptions_test 12. ./gtest_catch_exceptions_ex_test_ 13. ./gtest_catch_exceptions_no_ex_test_ 14. popd 15. mkdir build-optimized 16. pushd build-optimized 17. cmake -Dgtest_build_tests=ON ${GTEST_DIR} 18. VERBOSE=1 make CXX_FLAGS=-O gtest_catch_exceptions_ex_test_ gtest_catch_exceptions_no_ex_test_ 19. ctest -R gtest_catch_exceptions_test 20. ./gtest_catch_exceptions_ex_test_ 21. ./gtest_catch_exceptions_no_ex_test_ Actual results: "ctest -R gtest_catch_exceptions_test" passes when executables are compiled without optimization, but fails when compiled with optimization. When the compiled executables (./gtest_catch_exceptions_ex_test_ and ./gtest_catch_exceptions_no_ex_test_) are run directly from the command line, the UN-optimized versions run to completion with the gtest framework catching the exceptions. The optimized versions segfault--which is why the above "ctest ..." fails. Expected results: "ctest -R gtest_catch_exceptions_test" should always pass, regardless if the binaries are compiled with optimization or not. The compiled executables should not segfault when run directly, regardless if the binaries are compiled with optimization or not. Additional info: Upstream googletest framework is aware of this problem: https://github.com/google/googletest/issues/845 This issue is causing gtest-1.7.0 to fail to build from source in Fedora: https://bugzilla.redhat.com/show_bug.cgi?id=1406937
This is almost certainly a known bug in gtest, caused by calling member functions through a null pointer. See "Optimizations remove null pointer checks for this" at https://gcc.gnu.org/gcc-6/porting_to.html
The stack trace in the github issue confirms it, it shows this=0x0 at the point of failure. This is not a gcc bug. The code has undefined behaviour.
Using CXX_FLAGS="-O -fno-delete-null-pointer-checks" confirms it. Changing component to gtest, where the problem is.
Patch here: https://github.com/google/googletest/pull/967.patch Beware of bugs in the patch; I have only proved it correct, not tried it ;)
gtest-1.7.0-8.fc25 has been submitted as an update to Fedora 25. https://bodhi.fedoraproject.org/updates/FEDORA-2017-0caadc8ba7
gtest-1.7.0-8.fc24 has been submitted as an update to Fedora 24. https://bodhi.fedoraproject.org/updates/FEDORA-2017-cec378cd2f
gtest-1.7.0-8.fc24 has been pushed to the Fedora 24 testing repository. If problems still persist, please make note of it in this bug report. See https://fedoraproject.org/wiki/QA:Updates_Testing for instructions on how to install test updates. You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-cec378cd2f
gtest-1.7.0-8.fc25 has been pushed to the Fedora 25 testing repository. If problems still persist, please make note of it in this bug report. See https://fedoraproject.org/wiki/QA:Updates_Testing for instructions on how to install test updates. You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-0caadc8ba7
gtest-1.7.0-8.fc25 has been pushed to the Fedora 25 stable repository. If problems still persist, please make note of it in this bug report.
gtest-1.7.0-8.fc24 has been pushed to the Fedora 24 stable repository. If problems still persist, please make note of it in this bug report.