From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 321D43858D3C; Sun, 12 May 2024 19:41:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 321D43858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1715542868; bh=Hkby5XsMywlGdmV/AFaxuzwq1gsA8PQIOfc48Xiboqk=; h=From:To:Subject:Date:From; b=ZZWNA72+31IGikHg9+uPSmc3MxPkhQ4u8JNJWnHjKwcbHV3qJoK7sRzEfdinmPlom rnnsc/sdyoS3AYQvA7pQqb0Cn6M8hX3D4qY4bNlYg52hq/YXDC995GrCZxKitpSxiz M+B/K3Rt41d63KkLLjovRjLMrM7tVCES1Vy2GxjI= From: "franckbehaghel_gcc at protonmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/115052] New: rejected lambda while capturing a constexpr array Date: Sun, 12 May 2024 19:41:07 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 14.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: franckbehaghel_gcc at protonmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D115052 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[] =3D { 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[] =3D { 1, 2}; return [] (int i) { return a2[i];}(id); } In lambda function: :12:31: error: 'a2' is not captured 12 | return [] (int i) { return a2[i];}(id); | ^~ :12:12: note: the lambda has no capture-default 12 | return [] (int i) { return a2[i];}(id); | ^ :11:18: note: 'constexpr const int a2 [2]' declared here 11 | constexpr int a2[] =3D { 1, 2}; The second case seems also valid as it is just a change of scope. Moreover it is accepted by clang. regards,=