-
Notifications
You must be signed in to change notification settings - Fork 249
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] Can't interpolate captured function call #838
Comments
Looks like the issue here is that you're trying to do a lambda capture inside a string interpolation. That seems like it would be difficult at best to work out whether the |
If you want to capture |
That copies |
Thanks for waiting. The
Does that resolve the question for you? |
This works, too (https://cpp2.godbolt.org/z/4sTxqjW3G):
The problem seems to be the |
Interesting... my mental model for capture (including interpolation) has always been that it's referring to capture in the immediate context, here the string. This example is very interesting, because maybe it's pointing out that actually the model allows an interpolation to also mention a capture in the enclosing scope, by putting it in the interior of the interpolation... when the interpolation is applied, the implementation breaks the string into pieces... one of which contains an embedded interpolation. On thinking about it, that may make sense, but it was nonobvious to me that would fall out. Thanks for pointing this out! |
More: It's accidental that your example works... I did not intend to support nested captures like that. It happens to work because the code currently scans forward for the next For this case:
it appears to "work" because it just so happens that the expression contains a capture that is preserved when the string is broken into pieces... because there is no nested But for this case:
we find the first My (probably obvious) first reaction is to say "well, then scan for My second reaction is to regain consistency by actually rejecting both cases, including emitting an error on the first one by not allowing an interpolation to contain another |
Maybe rejecting them makes sense (and I'm fine with it, in this case), but I'm not sure. At which points does having a nested
|
Now I'm more sure that these aren't nested captures and shouldn't be rejected. My view is that string interpolation and a FE capture are similar operations, yet fundamentally different, that share a syntax
|
With regards to my expectations of #838 and #861, I think the grammar of string-literal isn't honest. |
Title: Can't interpolate function call.
Minimal reproducer (https://cpp2.godbolt.org/z/c7b34nGvo):
Commands:
cppfront main.cpp2 clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -I . main.cpp
Expected result: The second interpolation to work.
Actual result and error:
main.cpp2(3,27): error: no matching ( for string interpolation ending in )$
The text was updated successfully, but these errors were encountered: