From 72e1df8e7ca45fb5a796bf2fc721b0adc0d15614 Mon Sep 17 00:00:00 2001 From: Enrico Seiler Date: Mon, 5 Feb 2024 12:38:40 +0100 Subject: [PATCH] [FIX] gcc11,12 --- include/sharg/detail/poison_config.hpp | 25 +++++++++++++++++++++++++ include/sharg/parser.hpp | 7 +++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/include/sharg/detail/poison_config.hpp b/include/sharg/detail/poison_config.hpp index aa60ae94..94a2030a 100644 --- a/include/sharg/detail/poison_config.hpp +++ b/include/sharg/detail/poison_config.hpp @@ -89,4 +89,29 @@ concept poison_config_valid = (sizeof(poison_config) == sizeof(config, "sharg::detail::poison_config must have the same members as sharg::config!"); +/*!\brief This is a workaround for compilers that do not implement CWG2518 (GCC 11, GCC 12). + * \ingroup parser + * \sa https://en.cppreference.com/w/cpp/language/if#Constexpr_if + * \sa https://cplusplus.github.io/CWG/issues/2518.html + * \details + * Before CWG2518, a (discarded) statement couldn't be false in every case, e.g. + * ```cpp + * template + * void add_option(option_type) + * { + * if constexpr (std::is_same_v) + * { + * return; + * } + * else + * { + * static_assert(false, "Should never happen"); // invalid before CWG2518 + * static_assert(dependent_false_v, "Should never happen"); // valid + * } + * } + * ``` + */ +template +inline constexpr bool dependent_false_v = false; + } // namespace sharg::detail diff --git a/include/sharg/parser.hpp b/include/sharg/parser.hpp index 3f5f5b30..08753a01 100644 --- a/include/sharg/parser.hpp +++ b/include/sharg/parser.hpp @@ -263,7 +263,7 @@ class parser template void add_option(option_type &, detail::poison_config const &) { - static_assert(false, "Forgot sharg::config?"); + static_assert(detail::dependent_false_v, "Forgot sharg::config?"); } //!\endcond @@ -299,10 +299,9 @@ class parser //!\cond DEV //!\brief A poison overload that catches calls to add_flag without explicitly passing a sharg::config. template // Template needed to prevent instantiation of this function if unused. - requires std::same_as void add_flag(option_type &, detail::poison_config const &) { - static_assert(false, "Forgot sharg::config?"); + static_assert(detail::dependent_false_v, "Forgot sharg::config?"); } //!\endcond @@ -353,7 +352,7 @@ class parser template void add_positional_option(option_type &, detail::poison_config const &) { - static_assert(false, "Forgot sharg::config?"); + static_assert(detail::dependent_false_v, "Forgot sharg::config?"); } //!\endcond