Fix std::variant, std::filesystem::path tests on GCC-8, Clang-7,8. - #2951
Conversation
vitaut
left a comment
There was a problem hiding this comment.
Thanks for the PR. Unfortunately it only masks the issue so I suggest including <variant> in fmt/std.h when the header exists instead. This can be checked with FMT_HAS_INCLUDE.
2581e91 to
1ec4b82
Compare
|
@vitaut, Done. |
| #if FMT_HAS_INCLUDE(<version>) | ||
| # include <version> | ||
| #endif | ||
| #if FMT_CPLUSPLUS >= 201703L |
There was a problem hiding this comment.
What is this check for? Shouldn't FMT_HAS_INCLUDE and feature test macro checks be enough?
There was a problem hiding this comment.
Without FMT_CPLUSPLUS check:
libstdc++: ok (Checking the version of C++ standard is present)
libcxx: ok (Checking the version of C++ standard is absent)
MSVC message:
#if !_HAS_CXX17
#pragma message("The contents of <filesystem> are available only with C++17 or later.")
#else // ^^^ !_HAS_CXX17 / _HAS_CXX17 vvvhttps://github.com/microsoft/STL/blob/c34f24920e463a71791c2ee3d2bed14926518965/stl/inc/filesystem#L12-L14
https://github.com/microsoft/STL/blob/c34f24920e463a71791c2ee3d2bed14926518965/stl/inc/variant#L12-L14
https://godbolt.org/z/1MM9Kee8n
For this reason, a check is required.
There was a problem hiding this comment.
Could you add a short comment clarifying that this check is for MSVC?
| try_compile(compile_result_unused | ||
| ${CMAKE_CURRENT_BINARY_DIR} | ||
| SOURCES ${CMAKE_CURRENT_LIST_DIR}/detect-stdfs.cc | ||
| CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} | ||
| OUTPUT_VARIABLE RAWOUTPUT) | ||
| string(REGEX REPLACE ".*libfound \"([^\"]*)\".*" "\\1" STDLIBFS "${RAWOUTPUT}") | ||
| if (STDLIBFS) | ||
| target_link_libraries(std-test ${STDLIBFS}) | ||
| endif () |
There was a problem hiding this comment.
Is it possible to simplify this?
There was a problem hiding this comment.
The FS-library name is determined by the version of the C++ Standard Library.
CMake only determine the compiler version.
Clang supports libstdc++ and libcxx.
Intel C++ supports libstdc++ on Linux, libcxx on macOS, and Microsoft STL on Windows.
Therefore, the only way to determine which standard library is actually used is by compiling the code.
The code I wrote is the easiest way I know.
There was a problem hiding this comment.
Can this information be derived from CMAKE_CXX_STANDARD_LIBRARIES or CMAKE_CXX_IMPLICIT_LINK_LIBRARIES?
There was a problem hiding this comment.
The variable CMAKE_CXX_IMPLICIT_LINK_LIBRARIES allows to detect the standard library name, but not its version.
Example:
GCC-8:
CMAKE_CXX_IMPLICIT_LINK_LIBRARIES: stdc++;m;gcc_s;gcc;c;gcc_s;gcc
GCC-9:
CMAKE_CXX_IMPLICIT_LINK_LIBRARIES: stdc++;m;gcc_s;gcc;c;gcc_s;gcc
Clang 13 + libstdc++ (from GCC-11):
CMAKE_CXX_IMPLICIT_LINK_LIBRARIES: stdc++;m;gcc_s;gcc;c;gcc_s;gcc
Clang 13 + libc++:
CMAKE_CXX_IMPLICIT_LINK_LIBRARIES: c++;m;gcc_s;gcc;c;gcc_s;gcc
CMAKE_CXX_STANDARD_LIBRARIES - CMake 3.6+ and empty in most configurations
| // | ||
| // For the license information refer to format.h. | ||
|
|
||
| #include <exception> |
There was a problem hiding this comment.
The macros _GLIBCXX_RELEASE and _LIBCPP_VERSION is defined in standard library header files.
<exception> is the smallest of the standard library header files.
There was a problem hiding this comment.
I see. Maybe include <initializer_list> which is slightly cheaper according to https://artificial-mind.net/projects/compile-health/ and add a comment that this is for _GLIBCXX_RELEASE & _LIBCPP_VERSION?
There was a problem hiding this comment.
<initializer_list> is C++11.
Specifying the version of the standard will complicate the call to try_compile.
Comment added.
| try_compile(compile_result_unused | ||
| ${CMAKE_CURRENT_BINARY_DIR} | ||
| SOURCES ${CMAKE_CURRENT_LIST_DIR}/detect-stdfs.cc | ||
| CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} |
There was a problem hiding this comment.
Compiling detect-stdfs.cc and read compiler output to get fslib info from error message.
There was a problem hiding this comment.
I mean specifically the above line that forwards CMAKE_OSX_ARCHITECTURES.
There was a problem hiding this comment.
CMAKE_OSX_ARCHITECTURES affects the compiler but I'm not sure if it affects the standard library as well.
Removed it.
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
|
Merged, thanks! |
libstdc++from GCC-8 support std::variant.libstdc++from GCC-8 has no<version>file.libstdc++from GCC-8 defines the macro__cpp_lib_variantin<variant>.fmt/test/gtest/gtest/gtest.h
Lines 2621 to 2627 in 6a775e9
Because
gtest.hinclude<variant>, then the macro__cpp_lib_variantis defined in the test, but is not defined in"fmt/std.h".