-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[clang] reject to capture variable in RequiresExprBodyDecl
#78598
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
Changes from all commits
8fa3dc4
a99f16f
b27d0ac
402c84a
6cda600
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// RUN: %clang -fsyntax-only -std=c++20 -Xclang -verify %s | ||
|
||
// expected-no-diagnostics | ||
|
||
auto GH69307_correct() { | ||
constexpr auto b = 1; | ||
// no need to capture | ||
return [](auto c) -> int | ||
requires requires { b + c; } | ||
{ return 1; }; | ||
}; | ||
auto GH69307_correct_ret = GH69307_correct()(1); | ||
|
||
auto GH69307_func() { | ||
constexpr auto b = 1; | ||
return [&](auto c) -> int | ||
requires requires { b + c; } | ||
{ return 1; }; | ||
}; | ||
auto GH69307_func_ret = GH69307_func()(1); | ||
|
||
auto GH69307_lambda_1 = []() { | ||
return [&](auto c) -> int | ||
requires requires { c; } | ||
{ return 1; }; | ||
}; | ||
auto GH69307_lambda_1_ret = GH69307_lambda_1()(1); | ||
|
||
auto GH69307_lambda_2 = [](auto c) { | ||
return [&]() -> int | ||
requires requires { c; } | ||
{ return 1; }; | ||
}; | ||
auto GH69307_lambda_2_ret = GH69307_lambda_2(1)(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -Wunused-lambda-capture -Wused-but-marked-unused -Wno-uninitialized -verify -std=c++20 %s | ||
|
||
void test() { | ||
int i; | ||
auto explicit_by_value_unused_requires = [i] (auto) requires requires { i; } {}; // expected-warning{{lambda capture 'i' is not required to be captured for this use}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be PARTICULARLY good if we could 'remember' that it was 'used' in the requires clause so we can add a note that says something like (please consider wording and write better:)), There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be interesting. I will try to do it later in festival. |
||
explicit_by_value_unused_requires(1); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do a similar test with NO capture here? To show that they aren't needed.