Bug 105878 - Error message for const usage inside a capture should be improved
Summary: Error message for const usage inside a capture should be improved
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2022-06-08 01:01 UTC by Andrew Pinski
Modified: 2022-06-08 01:03 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2022-06-08 01:01:12 UTC
Take:
```
void f(int a)
{
  [& const a](){};
}
```
The current error message is:
```
<source>: In function 'void f(int)':
<source>:3:5: error: expected ',' before 'const'
    3 |   [& const a](){};
      |     ^~~~~~
      |     ,
<source>:3:6: error: expected identifier before 'const'
    3 |   [& const a](){};
      |      ^~~~~
```
clang gives:
```
<source>:3:6: error: expected variable name or 'this' in lambda capture list
  [& const a](){};
     ^
```
Which is slightly better.
but I think we could do better and say qualifers should not be in the capture list.