Skip to content

Commit c8c90e5

Browse files
committed
[Sema] Reword warning for constant captures that are not required
This is one of the darker corners of C++, make it clear that this is about constants and rephrase it a bit. Before: lambda capture 'i' is not required to be captured for this use After: lambda capture of constant 'i' is not required for this use llvm-svn: 337152
1 parent 0a7592b commit c8c90e5

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ def warn_unneeded_member_function : Warning<
341341
InGroup<UnneededMemberFunction>, DefaultIgnore;
342342
def warn_unused_private_field: Warning<"private field %0 is not used">,
343343
InGroup<UnusedPrivateField>, DefaultIgnore;
344-
def warn_unused_lambda_capture: Warning<"lambda capture %0 is not "
345-
"%select{used|required to be captured for this use}1">,
344+
def warn_unused_lambda_capture: Warning<"lambda capture "
345+
"%select{|of constant }1%0 is not %select{used|required for this use}1">,
346346
InGroup<UnusedLambdaCapture>, DefaultIgnore;
347347

348348
def warn_parameter_size: Warning<

clang/test/SemaCXX/warn-unused-lambda-capture.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ void test() {
4141
auto explicit_by_value_used = [i] { return i + 1; };
4242
auto explicit_by_value_used_void = [i] { (void)i; };
4343
auto explicit_by_value_unused = [i] {}; // expected-warning{{lambda capture 'i' is not used}}
44-
auto explicit_by_value_unused_sizeof = [i] { return sizeof(i); }; // expected-warning{{lambda capture 'i' is not required to be captured for this use}}
45-
auto explicit_by_value_unused_decltype = [i] { decltype(i) j = 0; }; // expected-warning{{lambda capture 'i' is not required to be captured for this use}}
46-
auto explicit_by_value_unused_const = [k] { return k + 1; }; // expected-warning{{lambda capture 'k' is not required to be captured for this use}}
44+
auto explicit_by_value_unused_sizeof = [i] { return sizeof(i); }; // expected-warning{{lambda capture of constant 'i' is not required for this use}}
45+
auto explicit_by_value_unused_decltype = [i] { decltype(i) j = 0; }; // expected-warning{{lambda capture of constant 'i' is not required for this use}}
46+
auto explicit_by_value_unused_const = [k] { return k + 1; }; // expected-warning{{lambda capture of constant 'k' is not required for this use}}
4747

4848
auto explicit_by_reference_used = [&i] { i++; };
4949
auto explicit_by_reference_unused = [&i] {}; // expected-warning{{lambda capture 'i' is not used}}
@@ -146,10 +146,10 @@ void test_templated() {
146146
auto explicit_by_value_used_void = [i] { (void)i; };
147147

148148
auto explicit_by_value_unused = [i] {}; // expected-warning{{lambda capture 'i' is not used}}
149-
auto explicit_by_value_unused_sizeof = [i] { return sizeof(i); }; // expected-warning{{lambda capture 'i' is not required to be captured for this use}}
149+
auto explicit_by_value_unused_sizeof = [i] { return sizeof(i); }; // expected-warning{{lambda capture of constant 'i' is not required for this use}}
150150
auto explicit_by_value_unused_decltype = [i] { decltype(i) j = 0; }; // expected-warning{{lambda capture 'i' is not used}}
151-
auto explicit_by_value_unused_const = [k] { return k + 1; }; // expected-warning{{lambda capture 'k' is not required to be captured for this use}}
152-
auto explicit_by_value_unused_const_generic = [k](auto c) { return k + 1; }; // expected-warning{{lambda capture 'k' is not required to be captured for this use}}
151+
auto explicit_by_value_unused_const = [k] { return k + 1; }; // expected-warning{{lambda capture of constant 'k' is not required for this use}}
152+
auto explicit_by_value_unused_const_generic = [k](auto c) { return k + 1; }; // expected-warning{{lambda capture of constant 'k' is not required for this use}}
153153

154154
auto explicit_by_reference_used = [&i] { i++; };
155155
auto explicit_by_reference_unused = [&i] {}; // expected-warning{{lambda capture 'i' is not used}}

0 commit comments

Comments
 (0)