-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
clang crash with return statement in statement-expression in default argument to lambda #53488
Labels
bug
Indicates an unexpected problem or unintended behavior
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
Comments
@llvm/issue-subscribers-clang-frontend |
@llvm/issue-subscribers-bug |
I think the minimal reproduce case should be: int main(){
auto f = [](char c = ({ return 42;})) {};
} g++ gives errors like:
|
A potential fix: https://reviews.llvm.org/D119609 |
Well yeah, because that statement-expression has the wrong type. Which is why I attached an example that actually does compile on gcc. |
mem-frob
pushed a commit
to draperlaboratory/hope-llvm-project
that referenced
this issue
Oct 7, 2022
As statement expression makes no sense in the default argument, this patch tries to disable it in the all cases. Please note that the statement expression is a GNU extension, which means that Clang should be consistent with GCC. However, there's no response from GCC devs since we have raised the issue for several weeks. In this case, I think we can disallow statement expressions as a default parameter in general for now, and relax the restriction if GCC folks decide to retain the feature for functions but not lambdas in the future. Related discussion: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104765 Fixes llvm/llvm-project#53488 Differential Revision: https://reviews.llvm.org/D119609
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
Indicates an unexpected problem or unintended behavior
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
GodBolt Link: https://godbolt.org/z/8rjxs4ab3
Program Source:
Crash Backtrace:
Note that gcc is able to compile this code correctly (GodBolt Link: https://godbolt.org/z/sGG3ddPrz). In invoking the lambda, it evaluates the default argument, runs the statement-expression, hits the return statement and correctly returns from the enclosing function.
This should be equivalent to the following:
Since having a default argument on a function should cause the same behavior as manually writing out that argument on every caller.
clang is able to compile this written-out version correctly.
The text was updated successfully, but these errors were encountered: