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

            Bug ID: 127799
           Summary: constexpr local used in requires-clause rejected
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mpolacek at gcc dot gnu.org
  Target Milestone: ---

```
void g(auto x) {
  constexpr int n = sizeof(x);
  auto v = [](auto t) requires (n > 0) {};
  v(0);
}

int main() { g(0); }
```

is wrongly rejected with 

bug1.C: In substitution of ‘template<class auto:2>
g<int>(int)::<lambda(auto:2)> [with auto:2 = int]’:
bug1.C:4:4:   required from ‘void g(auto:1) [with auto:1 = int]’
    4 |   v(0);
      |   ~^~~
bug1.C:7:15:   required from here
    7 | int main() { g(0); }
      |              ~^~~
bug1.C:3:12:   required by the constraints of ‘template<class auto:1>
template<class auto:2> g(auto:1)::<lambda(auto:2)>’
    3 |   auto v = [](auto t) requires (n > 0) {};
      |            ^
bug1.C:3:33: error: the value of ‘n’ is not usable in a constant expression
    3 |   auto v = [](auto t) requires (n > 0) {};
      |                                 ^
bug1.C:2:17: note: ‘n’ used in its own initializer
    2 |   constexpr int n = sizeof(x);
      |                 ^
bug1.C: In instantiation of ‘void g(auto:1) [with auto:1 = int]’:
bug1.C:7:15:   required from here
    7 | int main() { g(0); }
      |              ~^~~
bug1.C:4:4: error: no match for call to ‘(g<int>(int)::<lambda(auto:2)>) (int)’
    4 |   v(0);
      |   ~^~~
  • there is 1 candidate
    bug1.C:3:13:
        3 |   auto v = [](auto t) requires (n > 0) {};
          |             ^
    • candidate 1: ‘template<class auto:2> g<int>(int)::<lambda(auto:2)>’
      bug1.C:3:12:
          3 |   auto v = [](auto t) requires (n > 0) {};
            |            ^
      • substitution of deduced template arguments resulted in errors seen
above


Clang/EDG/MSVC accept the code.

Reply via email to