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

            Bug ID: 122494
           Summary: gcc rejects valid C++ codes
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rungecc at gmail dot com
  Target Milestone: ---

Reproducer(See online compiler: https://godbolt.org/z/bPnaMoY48):
```c++
template <typename Ts>
struct L {};

template <typename T>
struct S;

template <typename T>
concept C = requires { T::v; };

struct A {};
static_assert(!C<A>);

template <typename T> requires (!C<T>)
struct S<T> {
    constexpr static unsigned v = 0;
};

template <typename T>
struct S<L<T>> {
    // unsigned int or long or long long
    constexpr static unsigned v = S<T>::v;
    // generic lambda
    static_assert([](auto) {
        // "v == 0"
        if constexpr (v == 0) {}
        return true;
    }(1));
};

S<L<A>> _ = {};

int main() {}

```

Actual result:

g++15.2.0 with flat `-std=c++23`complains that

```
<source>: In instantiation of 'constexpr const unsigned int S<L<A> >::v':
<source>:25:23:   required from 'struct S<L<A> >'
   25 |         if constexpr (v == 0) {}
      |                       ^
<source>:30:9:   required from here
   30 | S<L<A>> _ = {};
      |         ^
<source>:21:41: error: incomplete type 'S<A>' used in nested name specifier
   21 |     constexpr static unsigned v = S<T>::v;
      |                                         ^
<source>: In instantiation of 'struct S<L<A> >':
<source>:30:9:   required from here
   30 | S<L<A>> _ = {};
      |         ^
<source>:27:6: error: non-constant condition for static assertion
   23 |     static_assert([](auto) {
      |                   ~~~~~~~~~~
   24 |         // "v == 0"
      |         ~~~~~~~~~~~
   25 |         if constexpr (v == 0) {}
      |         ~~~~~~~~~~~~~~~~~~~~~~~~
   26 |         return true;
      |         ~~~~~~~~~~~~
   27 |     }(1));
      |     ~^~~
<source>:27:6: error: 'S<L<A> >::<lambda(auto:1)> [with auto:1 = int]' called
in a constant expression
<source>:23:19: note: 'S<L<A> >::<lambda(auto:1)> [with auto:1 = int]' is not
usable as a 'constexpr' function because:
   23 |     static_assert([](auto) {
      |                   ^
Compiler returned: 1
```

Expected result, compiled successfully with no warnings, as msvc and clang++
do.

Reply via email to