Improve error message for invalid lambda captures (original) (raw)

For the following code (https://gcc.godbolt.org/z/GGoWq45hs) Clang produces an error message that some people find confusing:

struct X { int x; void foo() { x{}; } }; // :4:10: error: 'x' in capture list does not name a variable

It seems that the error message could indeed be improved, a few ideas that come to mind:

<source>:4:10: error: 'x' cannot be captured because it does not have automatic storage duration