1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-29 12:13:52 +00:00

update macros for codecvt and support C++26 support on clang19 (#1113)

* Modifies #1100 
* That PR comes from https://github.com/phlptp/CLI11 and unfortunately I
have no way of opening a PR to that repo, pointing to that branch...

The commit you care about is
9a2884ad6a
@phlptp

where I fix the build error on LLVM 19 with C++26 after rooting the
actual template issue (see
https://github.com/CLIUtils/CLI11/issues/1098#issuecomment-2572715578)

It comes down to C++26 adding a tuple interface to std::complex
https://en.cppreference.com/w/cpp/numeric/complex/tuple_size

---------

Co-authored-by: Philip Top <phlptp@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Julien Marrec 2025-01-11 14:42:24 +01:00 committed by GitHub
parent 7364157946
commit 10ac3e59a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 33 additions and 8 deletions

View File

@ -1,8 +1,8 @@
steps: steps:
# Note that silkeh/clang does not include ca-certificates, so check the shasum for verification # Note that silkeh/clang does not include ca-certificates, so check the shasum for verification
- bash: | - bash: |
wget --no-check-certificate "https://cmake.org/files/v3.28/cmake-3.28.0-linux-x86_64.tar.gz" wget --no-check-certificate "https://cmake.org/files/v3.31/cmake-3.31.1-linux-x86_64.tar.gz"
echo "898f0b5ca6e2ea5286998e97bd33f030d7d09f18ca4b88be661fdfbad5dadd88 cmake-3.28.0-linux-x86_64.tar.gz" | shasum -sca 256 echo "3b72fde0d40fa8be617667ea08d12c5ee47f6cf8950c2fbfcf2acfb5f83fb9de cmake-3.31.1-linux-x86_64.tar.gz" | shasum -sca 256
displayName: Download CMake displayName: Download CMake
- task: ExtractFiles@1 - task: ExtractFiles@1
@ -13,5 +13,5 @@ steps:
- bash: - bash:
echo echo
"##vso[task.prependpath]$(Build.SourcesDirectory)/cmake_program/cmake-3.28.0-linux-x86_64/bin" "##vso[task.prependpath]$(Build.SourcesDirectory)/cmake_program/cmake-3.31.1-linux-x86_64/bin"
displayName: Add CMake to PATH displayName: Add CMake to PATH

View File

@ -165,18 +165,22 @@ jobs:
vmImage: "ubuntu-latest" vmImage: "ubuntu-latest"
strategy: strategy:
matrix: matrix:
gcc13: gcc13_17:
containerImage: gcc:13 containerImage: gcc:13
cli11.std: 17 cli11.std: 17
cli11.options: -DCMAKE_CXX_FLAGS="-Wstrict-overflow=5" cli11.options: -DCMAKE_CXX_FLAGS="-Wstrict-overflow=5"
gcc12: gcc12_20:
containerImage: gcc:12 containerImage: gcc:12
cli11.std: 20 cli11.std: 20
cli11.options: -DCMAKE_CXX_FLAGS="-Wredundant-decls -Wconversion" cli11.options: -DCMAKE_CXX_FLAGS="-Wredundant-decls -Wconversion"
clang17_20: clang17_23:
containerImage: silkeh/clang:17 containerImage: silkeh/clang:17
cli11.std: 23 cli11.std: 23
cli11.options: -DCMAKE_CXX_FLAGS=-std=c++23 cli11.options: -DCMAKE_CXX_FLAGS=-std=c++23
clang19_26:
containerImage: silkeh/clang:19
cli11.std: 26
cli11.options: -DCMAKE_CXX_FLAGS=-std=c++2c
container: $[ variables['containerImage'] ] container: $[ variables['containerImage'] ]
steps: steps:
- template: .ci/azure-cmake-new.yml - template: .ci/azure-cmake-new.yml

View File

@ -18,11 +18,17 @@
#define CLI11_CPP17 #define CLI11_CPP17
#if __cplusplus > 201703L #if __cplusplus > 201703L
#define CLI11_CPP20 #define CLI11_CPP20
#if __cplusplus > 202002L
#define CLI11_CPP23
#if __cplusplus > 202302L
#define CLI11_CPP26
#endif
#endif
#endif #endif
#endif #endif
#endif #endif
#elif defined(_MSC_VER) && __cplusplus == 199711L #elif defined(_MSC_VER) && __cplusplus == 199711L
// MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard is fully implemented) // MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard was fully implemented)
// Unless you use the /Zc:__cplusplus flag on Visual Studio 2017 15.7 Preview 3 or newer // Unless you use the /Zc:__cplusplus flag on Visual Studio 2017 15.7 Preview 3 or newer
#if _MSVC_LANG >= 201402L #if _MSVC_LANG >= 201402L
#define CLI11_CPP14 #define CLI11_CPP14
@ -30,6 +36,9 @@
#define CLI11_CPP17 #define CLI11_CPP17
#if _MSVC_LANG > 201703L && _MSC_VER >= 1910 #if _MSVC_LANG > 201703L && _MSC_VER >= 1910
#define CLI11_CPP20 #define CLI11_CPP20
#if _MSVC_LANG > 202002L && _MSC_VER >= 1922
#define CLI11_CPP23
#endif
#endif #endif
#endif #endif
#endif #endif
@ -96,12 +105,22 @@
#endif #endif
/** <codecvt> availability */ /** <codecvt> availability */
#if !defined(CLI11_CPP26) && !defined(CLI11_HAS_CODECVT)
#if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) && __GNUC__ < 5 #if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) && __GNUC__ < 5
#define CLI11_HAS_CODECVT 0 #define CLI11_HAS_CODECVT 0
#else #else
#define CLI11_HAS_CODECVT 1 #define CLI11_HAS_CODECVT 1
#include <codecvt> #include <codecvt>
#endif #endif
#else
#if defined(CLI11_HAS_CODECVT)
#if CLI11_HAS_CODECVT > 0
#include <codecvt>
#endif
#else
#define CLI11_HAS_CODECVT 0
#endif
#endif
/** disable deprecations */ /** disable deprecations */
#if defined(__GNUC__) // GCC or clang #if defined(__GNUC__) // GCC or clang

View File

@ -295,8 +295,9 @@ template <typename T>
struct is_wrapper<T, conditional_t<false, void_t<typename T::value_type>, void>> : public std::true_type {}; struct is_wrapper<T, conditional_t<false, void_t<typename T::value_type>, void>> : public std::true_type {};
// Check for tuple like types, as in classes with a tuple_size type trait // Check for tuple like types, as in classes with a tuple_size type trait
// Even though in C++26 std::complex gains a std::tuple interface, for our purposes we treat is as NOT a tuple
template <typename S> class is_tuple_like { template <typename S> class is_tuple_like {
template <typename SS> template <typename SS, enable_if_t<!is_complex<SS>::value, detail::enabler> = detail::dummy>
// static auto test(int) // static auto test(int)
// -> decltype(std::conditional<(std::tuple_size<SS>::value > 0), std::true_type, std::false_type>::type()); // -> decltype(std::conditional<(std::tuple_size<SS>::value > 0), std::true_type, std::false_type>::type());
static auto test(int) -> decltype(std::tuple_size<typename std::decay<SS>::type>::value, std::true_type{}); static auto test(int) -> decltype(std::tuple_size<typename std::decay<SS>::type>::value, std::true_type{});

View File

@ -1520,6 +1520,7 @@ static_assert(CLI::detail::is_tuple_like<std::array<int, 10>>::value, "std::arra
static_assert(!CLI::detail::is_tuple_like<std::string>::value, "std::string should not be like a tuple"); static_assert(!CLI::detail::is_tuple_like<std::string>::value, "std::string should not be like a tuple");
static_assert(!CLI::detail::is_tuple_like<double>::value, "double should not be like a tuple"); static_assert(!CLI::detail::is_tuple_like<double>::value, "double should not be like a tuple");
static_assert(CLI::detail::is_tuple_like<std::tuple<double, int, double>>::value, "tuple should look like a tuple"); static_assert(CLI::detail::is_tuple_like<std::tuple<double, int, double>>::value, "tuple should look like a tuple");
static_assert(!CLI::detail::is_tuple_like<std::complex<double>>::value, "std::complex should not be like a tuple");
TEST_CASE("Types: LexicalConversionTuple2", "[helpers]") { TEST_CASE("Types: LexicalConversionTuple2", "[helpers]") {
CLI::results_t input = {"9.12", "19"}; CLI::results_t input = {"9.12", "19"};