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

            Bug ID: 115052
           Summary: rejected lambda while capturing a constexpr array
           Product: gcc
           Version: 14.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: franckbehaghel_gcc at protonmail dot com
  Target Milestone: ---

The following code is fine :

constexpr int a1[] = { 1, 2};
int f_lambda_capturing_case1(int id)
{
   return [] (int i) { return a1[i];}(id);
}



But this one is rejected :

int f_lambda_capturing_case2(int id)
{
   constexpr int a2[] = { 1, 2};
   return [] (int i) { return a2[i];}(id);
}



In lambda function:
<source>:12:31: error: 'a2' is not captured
   12 |    return [] (int i) { return a2[i];}(id);
      |                               ^~
<source>:12:12: note: the lambda has no capture-default
   12 |    return [] (int i) { return a2[i];}(id);
      |            ^
<source>:11:18: note: 'constexpr const int a2 [2]' declared here
   11 |    constexpr int a2[] = { 1, 2};



The second case seems also valid as it is just a change of scope.
Moreover it is accepted by clang.

regards,
  • [Bug c++/115052] New... franckbehaghel_gcc at protonmail dot com via Gcc-bugs

Reply via email to