0

I'm building the project with Clang 13.0.0 and I'm using libstdc++ 6.0.25 (system default). It's hard to use libc++ due to the dependencies. According to this table, my version of libstdc++ corresponds to GCC 8.1.0, which has a limited support for c++20 features. Below is a part of my CMakeLists.txt:

cmake_minimum_required(VERSION 3.17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
project(my_project LANGUAGES CXX)
...
add_executable(my_bin ...)
...
target_link_libraries(my_bin PRIVATE ... lstdc++ ...)

There is a feature-testing macro in one of the third-party libraries (gtest):

#ifdef __cpp_char8_t
...
#endif

And for some reason I end up with this macro enabled, though, according to this table char8t is only available since GCC 9. And after all the compilation fails. As far as I know, there is no way to 'undef' macro in make/cmake. Is there any idea how to get it working? Or, is it totally wrong to use clang 13 with an older libstdc++?

Update (the example of the code that fails, as requested in comments):

#ifdef __cpp_char8_t
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char8_t, ::std::u8string);    //<-- ln389
GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char8_t, ::std::u8string);
#endif

The following error occurs:

tools/google-test-1.11/googletest/include/gtest/gtest-printers.h:389:55: 
error: no member named 'u8string' in namespace 'std'

Update 2: Thank you Barry for pointing this out, indeed, the problem is in that __cpp_char8_t macro is insufficient for std::u8string (__cpp_lib_char8_t should be used for this), and it is clearly a bug in the gtest library. Sorry for not providing this from the start, my bad. Somehow I thought that gtest code shouldn't be wrong + didn't read the error message good enough.

Anton Pilyak
  • 900
  • 2
  • 11
  • 31
  • I don't follow the question. You said you're compiling with clang 13, and the table shows that clang has supported `char8_t` since clang 7, so what can't find what? – Barry Nov 11 '21 at 21:49
  • But still, I'm using stdlibc++ that comes with the OS, and not the libc++ that goes with Clang 13. Compiling with -stdlib=libc++ fixes this problem, but I can't do this due to a big amount of dependencies. – Anton Pilyak Nov 11 '21 at 22:03
  • 1
    This doesn't seem to be a cmake problem, unless you can't get cmake to specify the correct compiler options. Assuming you're using unix makefiles you can add the `--verbose` option to your `cmake --build` command to see the exact command used for the compilation... – fabian Nov 11 '21 at 22:12
  • Don't claim to support C++20 if the library you're using does not? – Yakk - Adam Nevraumont Nov 11 '21 at 22:33
  • @fabian, the compiler options seem to be ok to me, nothing unexpected there: -std=c++20a, all the other usual stuff... – Anton Pilyak Nov 11 '21 at 22:37
  • @Yakk: libstd++ 6.0.25 should partly support c++20, the problem is that the macros don't work correctly for some reason, and this leads to build error=( – Anton Pilyak Nov 11 '21 at 22:41
  • 1
    @AntonPilyak Do you have an example of code that fails? What build error? – Barry Nov 11 '21 at 23:29
  • @Barry, /gtest-printers.h:389:55: error: no member named 'u8string' in namespace 'std' – Anton Pilyak Nov 12 '21 at 10:34
  • 1
    @AntonPilyak I mean, that's something that should be in the question. That's what's expected, see [ask]. In this case though, `__cpp_char8_t` only tells you if you have `char8_t`. If you need `std::u8string`, that's `__cpp_lib_char8_t`. – Barry Nov 12 '21 at 14:52
  • @Barry, thanks, yes, I indeed missed the point that __cpp_char8_t is only for char8_t. But, anyway, it is a 3rd party library header, that is why I was mostly looking for a way to disable __cpp_char8_t at all in the whole project. Plus, somehow I was sure that the google library code should be alright - that's why I didn't include the sources from the beginning, sorry. – Anton Pilyak Nov 12 '21 at 15:08

0 Answers0