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

            Bug ID: 123889
           Summary: C++11 diagnostic about non-constexpr functions is
                    useless
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nikolasklauser at berlin dot de
  Target Milestone: ---

```
template <class T>
constexpr int func(T) {
  return 1;
  return 2;
}

static_assert(func(1) == 1);
```

generates the following error:
<source>:9:23: error: non-constant condition for static assertion
    9 | static_assert(func(1) == 1);
      |               ~~~~~~~~^~~~
<source>:9:19: error: 'constexpr int func(T) [with T = int]' called in a
constant expression
    9 | static_assert(func(1) == 1);
      |               ~~~~^~~
<source>:4:15: note: 'constexpr int func(T) [with T = int]' is not usable as a
'constexpr' function because:
    4 | constexpr int func(T) {
      |               ^~~~

This error is 100% useless, as it doesn't tell me at all what's wrong.

On a side note, it would be nice if GCC didn't error on more than a single
return statement in C++11 mode, since Clang allows more complex expressions as
an extension already (and also happens to issue a usable warning in this
example).

It looks like the diagnostic was better in GCC 11.

Reply via email to