-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Variable initialized after equally named capture rejected #1312
Comments
For context, this is the discussion where the current error was introduced: #1028 I swore this reproducer code should not work, because of a variety of reasons, such as this having to require that the name lookup for I was going to argue that the new name exists as soon as the
Then it actually worked. This is when my brain broke.
So the Right this minute I am very much not in favor of this. I am a bit okay with the local I don't like at all the local scope bypass on I am also fine with the original example failing with either the self-assignment error or the not eligible for capture error, since there are technically two errors there if Another reason to not like this is that this
Documentation:
I know that this says that the capture is evaluated at the point where the function expression is written and the point where the string literal is written, and I was 100% on board with that until now. It doesn't explicitly mention lookup scope, and I didn't expect it to until now. While capture is spelled the same way in all contexts, it doesn't have the same scope in all contexts. It means that if I am in a lambda and take the first line below and refactor it into the second, I get a different variable, and that's just way too subtle.
PS. Here is the error when you attempt to do a lambda capture of a local variable, it's not what you'd expect:
|
Title: Variable initialized after equally named capture rejected.
Minimal reproducer (https://cpp2.godbolt.org/z/MPYnY1qbM):
Commands:
cppfront main.cpp2 clang++-18 -std=c++26 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -Werror=unused-value -Werror=unused-parameter -Werror=unused-variable -I . main.cpp
Expected result: A working program.
Actual result and error:
Output:See also:
The text was updated successfully, but these errors were encountered: