]> granicus.if.org Git - clang/commitdiff
[Sema] Reword unused lambda capture warning
authorMalcolm Parsons <malcolm.parsons@gmail.com>
Thu, 19 Jan 2017 17:19:22 +0000 (17:19 +0000)
committerMalcolm Parsons <malcolm.parsons@gmail.com>
Thu, 19 Jan 2017 17:19:22 +0000 (17:19 +0000)
Summary:
The warning doesn't know why the variable was looked up but not
odr-used, so reword it to not claim that it was used in an unevaluated
context.

Reviewers: aaron.ballman

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D28902

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@292498 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
test/SemaCXX/warn-unused-lambda-capture.cpp

index e0a5073483d9c3f3668a3a6d1e57b8569f159022..42e91bcda75c127afb1428d112f66731dd5cc680 100644 (file)
@@ -320,7 +320,7 @@ def warn_unneeded_member_function : Warning<
 def warn_unused_private_field: Warning<"private field %0 is not used">,
   InGroup<UnusedPrivateField>, DefaultIgnore;
 def warn_unused_lambda_capture: Warning<"lambda capture %0 is not "
-  "%select{used|required to be captured for use in an unevaluated context}1">,
+  "%select{used|required to be captured for this use}1">,
   InGroup<UnusedLambdaCapture>, DefaultIgnore;
 
 def warn_parameter_size: Warning<
index 18c5d6483d22ff2e62f0ad262a28c77e82ec7a5d..f4b1c92637d2275708968bc7c5b0e637b9091980 100644 (file)
@@ -22,6 +22,7 @@ int side_effect() {
 
 void test() {
   int i = 0;
+  const int k = 0;
 
   auto captures_nothing = [] {};
 
@@ -34,8 +35,9 @@ void test() {
   auto explicit_by_value_used = [i] { return i + 1; };
   auto explicit_by_value_used_void = [i] { (void)i; };
   auto explicit_by_value_unused = [i] {}; // expected-warning{{lambda capture 'i' is not used}}
-  auto explicit_by_value_unused_sizeof = [i] { return sizeof(i); }; // expected-warning{{lambda capture 'i' is not required to be captured for use in an unevaluated context}}
-  auto explicit_by_value_unused_decltype = [i] { decltype(i) j = 0; }; // expected-warning{{lambda capture 'i' is not required to be captured for use in an unevaluated context}}
+  auto explicit_by_value_unused_sizeof = [i] { return sizeof(i); }; // expected-warning{{lambda capture 'i' is not required to be captured for this use}}
+  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}}
+  auto explicit_by_value_unused_const = [k] { return k + 1; };         // expected-warning{{lambda capture 'k' is not required to be captured for this use}}
 
   auto explicit_by_reference_used = [&i] { i++; };
   auto explicit_by_reference_unused = [&i] {}; // expected-warning{{lambda capture 'i' is not used}}
@@ -70,6 +72,7 @@ class Foo
 template <typename T>
 void test_templated() {
   int i = 0;
+  const int k = 0;
 
   auto captures_nothing = [] {};
 
@@ -82,8 +85,9 @@ void test_templated() {
   auto explicit_by_value_used = [i] { return i + 1; };
   auto explicit_by_value_used_void = [i] { (void)i; };
   auto explicit_by_value_unused = [i] {}; // expected-warning{{lambda capture 'i' is not used}}
-  auto explicit_by_value_unused_sizeof = [i] { return sizeof(i); }; // expected-warning{{lambda capture 'i' is not required to be captured for use in an unevaluated context}}
+  auto explicit_by_value_unused_sizeof = [i] { return sizeof(i); }; // expected-warning{{lambda capture 'i' is not required to be captured for this use}}
   auto explicit_by_value_unused_decltype = [i] { decltype(i) j = 0; }; // expected-warning{{lambda capture 'i' is not used}}
+  auto explicit_by_value_unused_const = [k] { return k + 1; };         // expected-warning{{lambda capture 'k' is not required to be captured for this use}}
 
   auto explicit_by_reference_used = [&i] { i++; };
   auto explicit_by_reference_unused = [&i] {}; // expected-warning{{lambda capture 'i' is not used}}