catchorg / Catch2

A modern, C++-native, test framework for unit-tests, TDD and BDD - using C++14, C++17 and later (C++11 support is in v2.x branch, and C++03 on the Catch1.x branch)
https://discord.gg/4CWS9zD
Boost Software License 1.0
18.56k stars 3.05k forks source link

Failed to compile Catch v2.2.1 with Clang 5.0.2 in Travis CI's linux server #1248

Closed xsun2001 closed 4 years ago

xsun2001 commented 6 years ago

Description

Build failed after I changed set(CMAKE_CXX_STANDARD 14) to set(CMAKE_CXX_STANDARD 17).

In file included from /home/travis/build/ChinaCreators/LHL/LML/Tests/Tests.cpp:4:
/home/travis/build/ChinaCreators/LHL/Catch/catch.hpp:10771:16: error: no member named 'uncaught_exceptions' in namespace 'std'; did you mean simply 'uncaught_exceptions'?
        return std::uncaught_exceptions() > 0;
               ^~~~~
/home/travis/build/ChinaCreators/LHL/Catch/catch.hpp:10769:10: note: 'uncaught_exceptions' declared here
    bool uncaught_exceptions() {
         ^
1 error generated.
make[2]: *** [LML/CMakeFiles/LMLTest.dir/Tests/Tests.cpp.o] Error 1
make[1]: *** [LML/CMakeFiles/LMLTest.dir/all] Error 2
make: *** [all] Error 2

Steps to reproduce

Extra information

horenmar commented 6 years ago

~Do you have CMake in version 3.8 or later? Earlier versions of CMake do not recognize 17 as a valid value for CMAKE_CXX_STANDARD and silently fall back to whatever is the default.~

Nevermind, if that was the problem, the compilation error would be a different one. The problem here is that whatever stdlib you are using does not provide std::uncaught_exceptions in C++17 mode. You can force Catch to fallback to std::uncaught_exception by defining CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS.

acgetchell commented 6 years ago

Thanks, I had the same issue and this fixed it!

ClangTidy doesn't like it though.

https://travis-ci.org/acgetchell/CDT-plusplus/builds/420808766

horenmar commented 6 years ago

@acgetchell To me it seems less like ClangTidy doesn't work with the define and more like your compilation database is broken:

$ git diff -U0 HEAD^ | /usr/lib/llvm-6.0/share/clang/clang-tidy-diff.py > output.txt
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "b/tests/main.cpp"
No compilation database found in /home/travis/build/acgetchell/CDT-plusplus/b/tests or any parent directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
Error reading configuration from /home/travis/build/acgetchell/CDT-plusplus/b/tests: directory doesn't exist.
Error reading configuration from /home/travis/build/acgetchell/CDT-plusplus/b: directory doesn't exist.
1 error generated.
Error while processing /home/travis/build/acgetchell/CDT-plusplus/b/tests/main.cpp.
horenmar commented 4 years ago

Should be fixed, just as #1218.