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:
- mentioning what kind of symbol we are actually referring to:
'class member 'x' cannot appear in capture list as it is not a variable' - we could suggest fixes in some situations
did you mean to capture 'this'?ordid you mean to use a capture with initializer? variableis technically correct and what Clang is using, but maybe it would be better to saylocal variable or parameter? I might be missing some cases, but it sounds more user-friendly than the similar error about "automatic storage duration` that we have today:
<source>:4:10: error: 'x' cannot be captured because it does not have automatic storage duration