https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117272

            Bug ID: 117272
           Summary: CWG2518 static_assert(false) when returning
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Richard1.Kellnberger at web dot de
  Target Milestone: ---

Since gcc 13 this is valid code:

```C++
template<typename T> void f(){
    static_assert(false);
}

int main() {

}
```

This is as well:

```C++
#include <type_traits>

template<typename T> void f(){
    if constexpr(std::is_same_v<T, int>) {

    } else {
        static_assert(false);
    }
}

int main() {
    f<int>();
}
```

The `static_assert(false)` is ignored if it is not reached due to templating.
If I placed it into the `if` block instead the code would be ill-formed.
By the same logic the following should be valid, but it is not.

```C++
#include <type_traits>

template<typename T> void f(){
    if constexpr(std::is_same_v<T, int>) {
        return;
    }
    static_assert(false);
}

int main() {
    f<int>();
}
```

Reply via email to