Skip to content

Commit

Permalink
[FIX] gcc11,12
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Feb 5, 2024
1 parent b4b9445 commit 72e1df8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
25 changes: 25 additions & 0 deletions include/sharg/detail/poison_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,29 @@ concept poison_config_valid = (sizeof(poison_config) == sizeof(config<validator_

static_assert(poison_config_valid<>, "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 <typename option_type>
* void add_option(option_type)
* {
* if constexpr (std::is_same_v<option_type, int>)
* {
* return;
* }
* else
* {
* static_assert(false, "Should never happen"); // invalid before CWG2518
* static_assert(dependent_false_v<option_type>, "Should never happen"); // valid
* }
* }
* ```
*/
template <typename>
inline constexpr bool dependent_false_v = false;

} // namespace sharg::detail
7 changes: 3 additions & 4 deletions include/sharg/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class parser
template <typename option_type>
void add_option(option_type &, detail::poison_config const &)
{
static_assert(false, "Forgot sharg::config?");
static_assert(detail::dependent_false_v<option_type>, "Forgot sharg::config?");
}
//!\endcond

Expand Down Expand Up @@ -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 <typename option_type> // Template needed to prevent instantiation of this function if unused.
requires std::same_as<option_type, bool>
void add_flag(option_type &, detail::poison_config const &)
{
static_assert(false, "Forgot sharg::config?");
static_assert(detail::dependent_false_v<option_type>, "Forgot sharg::config?");
}
//!\endcond

Expand Down Expand Up @@ -353,7 +352,7 @@ class parser
template <typename option_type>
void add_positional_option(option_type &, detail::poison_config const &)
{
static_assert(false, "Forgot sharg::config?");
static_assert(detail::dependent_false_v<option_type>, "Forgot sharg::config?");
}
//!\endcond

Expand Down

0 comments on commit 72e1df8

Please sign in to comment.