public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115052] New: rejected lambda while capturing a constexpr array
@ 2024-05-12 19:41 franckbehaghel_gcc at protonmail dot com
2024-05-28 15:33 ` [Bug c++/115052] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: franckbehaghel_gcc at protonmail dot com @ 2024-05-12 19:41 UTC (permalink / raw)
To: gcc-bugs
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,
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-05-28 15:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-12 19:41 [Bug c++/115052] New: rejected lambda while capturing a constexpr array franckbehaghel_gcc at protonmail dot com
2024-05-28 15:33 ` [Bug c++/115052] " pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).