From: Benjamin Kramer Date: Mon, 16 Jul 2018 09:52:02 +0000 (+0000) Subject: [Sema] Reword warning for constant captures that are not required X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fd9658b9daae8d49632f151dce9354765ea2b190;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337152 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 1915f7e3be..c32b5ea07a 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -341,8 +341,8 @@ def warn_unneeded_member_function : Warning< InGroup, DefaultIgnore; def warn_unused_private_field: Warning<"private field %0 is not used">, InGroup, DefaultIgnore; -def warn_unused_lambda_capture: Warning<"lambda capture %0 is not " - "%select{used|required to be captured for this use}1">, +def warn_unused_lambda_capture: Warning<"lambda capture " + "%select{|of constant }1%0 is not %select{used|required for this use}1">, InGroup, DefaultIgnore; def warn_parameter_size: Warning< diff --git a/test/SemaCXX/warn-unused-lambda-capture.cpp b/test/SemaCXX/warn-unused-lambda-capture.cpp index 52ec390b0b..f1f0c9e2bc 100644 --- a/test/SemaCXX/warn-unused-lambda-capture.cpp +++ b/test/SemaCXX/warn-unused-lambda-capture.cpp @@ -41,9 +41,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 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_value_unused_sizeof = [i] { return sizeof(i); }; // expected-warning{{lambda capture of constant 'i' is not required for this use}} + auto explicit_by_value_unused_decltype = [i] { decltype(i) j = 0; }; // expected-warning{{lambda capture of constant 'i' is not required for this use}} + auto explicit_by_value_unused_const = [k] { return k + 1; }; // expected-warning{{lambda capture of constant 'k' is not required for this use}} auto explicit_by_reference_used = [&i] { i++; }; auto explicit_by_reference_unused = [&i] {}; // expected-warning{{lambda capture 'i' is not used}} @@ -146,10 +146,10 @@ void test_templated() { 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 this use}} + auto explicit_by_value_unused_sizeof = [i] { return sizeof(i); }; // expected-warning{{lambda capture of constant 'i' is not required 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_value_unused_const_generic = [k](auto c) { return k + 1; }; // expected-warning{{lambda capture 'k' is not required to be captured for this use}} + auto explicit_by_value_unused_const = [k] { return k + 1; }; // expected-warning{{lambda capture of constant 'k' is not required for this use}} + 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}} auto explicit_by_reference_used = [&i] { i++; }; auto explicit_by_reference_unused = [&i] {}; // expected-warning{{lambda capture 'i' is not used}}