Skip to content

Conversation

@Yan-Zero
Copy link

Change "false" to "N > 4 || N < 0" in static_assert

Only the GCC version above 13.0 can compile the code like:

template<typename T>
void f()
{
    if constexpr ([std::is_arithmetic_v](http://en.cppreference.com/w/cpp/types/is_arithmetic)<T>)
        // ...
    else {
        using invalid_array = int[-1]; // ill-formed: invalid for every T
        static_assert(false, "Must be arithmetic"); // ill-formed before CWG2518
    }
}

(from cppreference)

Before CWG2518, we can code:

template<typename>
inline constexpr bool dependent_false_v = false;
 
template<typename T>
void f()
{
    if constexpr ([std::is_arithmetic_v](http://en.cppreference.com/w/cpp/types/is_arithmetic)<T>)
        // ...
    else {
        // workaround before CWG2518
        static_assert(dependent_false_v<T>, "Must be arithmetic");
    }
}

Change "false" to "N > 4 || N < 0" in static_assert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant