Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++17 std::byte detection fails on ubuntu+clang-6.0 #1992

Closed
gnbond opened this issue Jul 30, 2020 · 3 comments · Fixed by #1996
Closed

C++17 std::byte detection fails on ubuntu+clang-6.0 #1992

gnbond opened this issue Jul 30, 2020 · 3 comments · Fixed by #1996
Labels

Comments

@gnbond
Copy link
Contributor

gnbond commented Jul 30, 2020

Describe the bug
Clang6 and clang8 in c++17 mode cannot compile catch unit tests

Expected behavior
C++17 should be supported

Reproduction steps
Ubuntu 16, clang++6.0 (and clang++-8) installed with "apt install clang6.0"
Simple null unit test:

#include "catch.hpp"
TEST_CASE("simple", "[simple]") {
}
$ clang++-6.0 -std=c++17 -c cb.cpp 
In file included from cb.cpp:1:
./catch.hpp:1735:29: error: no member named 'byte' in namespace 'std'
    struct StringMaker<std::byte> {
                       ~~~~~^
1 error generated.

Platform information:

  • OS: ubuntu 16

  • Compiler+version:
    clang version 6.0.0-1ubuntu2~16.04.1 (tags/RELEASE_600/final)
    Target: x86_64-pc-linux-gnu
    Thread model: posix
    InstalledDir: /usr/bin

  • Catch version: v2.13.0 downloaded in the single file version

Additional context
Also happens with clang-8 package.
Compiles fine in clang-6 or clang-8 in c+11 or c++14 mode.

This may be a packaging error in ubuntu, or it might be I have not installed some vital piece, or need to configure clang to use a better standard library or something.

@arobenko
Copy link

arobenko commented Jul 31, 2020

@gnbond
I had similar problem and worked around it by adding the CATCH_CONFIG_NO_CPP17_BYTE definition:

    target_compile_options(my_binary PRIVATE
      $<$<CXX_COMPILER_ID:Clang>:-DCATCH_CONFIG_NO_CPP17_BYTE=1>
    )

@gnbond
Copy link
Contributor Author

gnbond commented Jul 31, 2020

After a bunch more experimentation, this appears to be a ubuntu 16-specific issue, clang packages on ubuntu-18 (and FreeBSD 11) work fine. I think the issue is the clang packages are still using OS-default standard library, which is g++5 on ubuntu-16, and g++5 version of <cstddef> does not have std::byte.

The below patch seems to fix it, and seems in the spirit of the feature test macros , but I do not know if there are any adverse consequences of #including in this circumstance.

(line numbers are the single-file version 2.13.0)

 --- a/catch.hpp
+++ b/catch.hpp
@@ -330,7 +330,10 @@ namespace Catch {
 
   // Check if byte is available and usable
   #  if __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER)
-  #    define CATCH_INTERNAL_CONFIG_CPP17_BYTE
+  #    include <cstddef>
+  #    if __cpp_lib_byte
+  #      define CATCH_INTERNAL_CONFIG_CPP17_BYTE
+  #    endif
   #  endif // __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER)
 
   // Check if variant is available and usable

@horenmar horenmar added the Bug label Aug 1, 2020
gnbond added a commit to gnbond/Rectangular that referenced this issue Aug 2, 2020
@horenmar
Copy link
Member

horenmar commented Aug 2, 2020

Yeah, some feature checks still use the old and wrong way of doing them -- it is a legacy of most feature checks being for C++11/14, which did not have feature macros, so checking for C++ standard and then hoping for the best was a reasonable option.

If you open up a PR, I will merge it, otherwise it will have to wait until I get around to working on v2 branch again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants