File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed
Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -89,4 +89,29 @@ concept poison_config_valid = (sizeof(poison_config) == sizeof(config<validator_
8989
9090static_assert (poison_config_valid<>, " sharg::detail::poison_config must have the same members as sharg::config!" );
9191
92+ /* !\brief This is a workaround for compilers that do not implement CWG2518 (GCC 11, GCC 12).
93+ * \ingroup parser
94+ * \sa https://en.cppreference.com/w/cpp/language/if#Constexpr_if
95+ * \sa https://cplusplus.github.io/CWG/issues/2518.html
96+ * \details
97+ * Before CWG2518, a (discarded) statement couldn't be false in every case, e.g.
98+ * ```cpp
99+ * template <typename option_type>
100+ * void add_option(option_type)
101+ * {
102+ * if constexpr (std::is_same_v<option_type, int>)
103+ * {
104+ * return;
105+ * }
106+ * else
107+ * {
108+ * static_assert(false, "Should never happen"); // invalid before CWG2518
109+ * static_assert(dependent_false_v<option_type>, "Should never happen"); // valid
110+ * }
111+ * }
112+ * ```
113+ */
114+ template <typename >
115+ inline constexpr bool dependent_false_v = false ;
116+
92117} // namespace sharg::detail
Original file line number Diff line number Diff line change @@ -263,7 +263,7 @@ class parser
263263 template <typename option_type>
264264 void add_option (option_type &, detail::poison_config const &)
265265 {
266- static_assert (false , " Forgot sharg::config?" );
266+ static_assert (detail::dependent_false_v<option_type> , " Forgot sharg::config?" );
267267 }
268268 // !\endcond
269269
@@ -301,7 +301,7 @@ class parser
301301 template <typename option_type> // Template needed to prevent instantiation of this function if unused.
302302 void add_flag (option_type &, detail::poison_config const &)
303303 {
304- static_assert (false , " Forgot sharg::config?" );
304+ static_assert (detail::dependent_false_v<option_type> , " Forgot sharg::config?" );
305305 }
306306 // !\endcond
307307
@@ -352,7 +352,7 @@ class parser
352352 template <typename option_type>
353353 void add_positional_option (option_type &, detail::poison_config const &)
354354 {
355- static_assert (false , " Forgot sharg::config?" );
355+ static_assert (detail::dependent_false_v<option_type> , " Forgot sharg::config?" );
356356 }
357357 // !\endcond
358358
You can’t perform that action at this time.
0 commit comments