From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 78BD93858C56; Wed, 4 May 2022 08:08:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 78BD93858C56 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-101] c++: Don't emit deprecated warnings or unavailable errors on lambda declarations X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 3771486daa1e904ceae6f3e135b28e58af33849f X-Git-Newrev: 1c8e9bed9b9d46d479b83ae05b334543f66961fb Message-Id: <20220504080849.78BD93858C56@sourceware.org> Date: Wed, 4 May 2022 08:08:49 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 May 2022 08:08:49 -0000 https://gcc.gnu.org/g:1c8e9bed9b9d46d479b83ae05b334543f66961fb commit r13-101-g1c8e9bed9b9d46d479b83ae05b334543f66961fb Author: Jakub Jelinek Date: Wed May 4 10:07:36 2022 +0200 c++: Don't emit deprecated warnings or unavailable errors on lambda declarations On the following testcase, we emit deprecated warnings or unavailable errors even on merge declarations of those lambdas (the dg-bogus directives), while IMHO we should emit them only when something actually calls those lambdas. The following patch temporarily disables that diagnostics during maybe_add_lambda_conv_op. PR2173R1 also says that ambiguity between attribute-specifier-seq at the end of requires-clause and attribute-specifier-seq from lambda-expression should be resolved to attribute-specifier-seq for the latter. Do we need to do anything about that? I mean, can a valid requires-clause end with an attribute-specifier-seq? Say operator int [[]] is valid primary expression, but requires operator int [[]] isn't valid, nor is requires operator int, no? 2022-05-04 Jakub Jelinek * lambda.cc: Include decl.h. (maybe_add_lambda_conv_op): Temporarily override deprecated_state to UNAVAILABLE_DEPRECATED_SUPPRESS. * g++.dg/cpp23/lambda-attr1.C: New test. * g++.dg/cpp23/lambda-attr2.C: New test. Diff: --- gcc/cp/lambda.cc | 12 +++++++--- gcc/testsuite/g++.dg/cpp23/lambda-attr1.C | 37 +++++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp23/lambda-attr2.C | 19 ++++++++++++++++ 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc index 10834d6b143..afac53b6d7c 100644 --- a/gcc/cp/lambda.cc +++ b/gcc/cp/lambda.cc @@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see #include "toplev.h" #include "gimplify.h" #include "target.h" +#include "decl.h" /* Constructor for a lambda expression. */ @@ -1192,9 +1193,14 @@ maybe_add_lambda_conv_op (tree type) } } else - call = build_call_a (callop, - direct_argvec->length (), - direct_argvec->address ()); + { + /* Don't warn on deprecated or unavailable lambda declarations, unless + the lambda is actually called. */ + auto du = make_temp_override (deprecated_state, + UNAVAILABLE_DEPRECATED_SUPPRESS); + call = build_call_a (callop, direct_argvec->length (), + direct_argvec->address ()); + } CALL_FROM_THUNK_P (call) = 1; SET_EXPR_LOCATION (call, UNKNOWN_LOCATION); diff --git a/gcc/testsuite/g++.dg/cpp23/lambda-attr1.C b/gcc/testsuite/g++.dg/cpp23/lambda-attr1.C new file mode 100644 index 00000000000..a653c732fca --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/lambda-attr1.C @@ -0,0 +1,37 @@ +// P2173R1 - Attributes on Lambda-Expressions +// { dg-do compile { target c++11 } } + +void +foo (bool x, bool y) +{ + auto a = [][[noreturn]] () {}; // { dg-warning "'noreturn' function does return" } + if (x) + a (); + auto b = [][[noreturn]] {}; // { dg-warning "'noreturn' function does return" } + if (y) + b (); + auto c = [] [[ deprecated ]] () {}; // { dg-bogus "is deprecated" } + c (); // { dg-warning "'foo\\\(bool, bool\\\)::' is deprecated" } + auto d = [][[deprecated]] {}; // { dg-bogus "is deprecated" } + d (); // { dg-warning "'foo\\\(bool, bool\\\)::' is deprecated" } +#if __cpp_generic_lambdas >= 201304 + auto e = [] [[deprecated]] (auto x) {}; // { dg-bogus "is deprecated" } + e (0.0); // { dg-warning "'foo\\\(bool, bool\\\)::\[^\n\r]*' is deprecated" "" { target c++14 } } +#endif +#if __cpp_generic_lambdas >= 201707 + auto f = [] [[deprecated]] (T) {}; // { dg-bogus "is deprecated" } + f (1); // { dg-warning "'foo\\\(bool, bool\\\)::\[^\n\r]*' is deprecated" "" { target c++20 } } +#endif + auto g = [][[nodiscard]](int) { return 1; }; + g (1); // { dg-warning "ignoring return value of 'foo\\\(bool, bool\\\)::', declared with attribute 'nodiscard'" } + auto h = [] [[nodiscard]] { return 0; }; + h (); // { dg-warning "ignoring return value of 'foo\\\(bool, bool\\\)::', declared with attribute 'nodiscard'" } + auto i = [] [[ gnu::unavailable ]] () {}; + auto j = [][[gnu::unavailable]] {}; +#if __cpp_generic_lambdas >= 201304 + auto k = [] [[gnu::unavailable]] (auto x) {}; // { dg-bogus "is unavailable" } +#endif +#if __cpp_generic_lambdas >= 201707 + auto l = [] [[gnu::unavailable]] (T) {}; // { dg-bogus "is unavailable" } +#endif +} diff --git a/gcc/testsuite/g++.dg/cpp23/lambda-attr2.C b/gcc/testsuite/g++.dg/cpp23/lambda-attr2.C new file mode 100644 index 00000000000..0392b179b86 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/lambda-attr2.C @@ -0,0 +1,19 @@ +// P2173R1 - Attributes on Lambda-Expressions +// { dg-do compile { target c++11 } } + +void +foo (bool x, bool y) +{ + auto i = [] [[ gnu::unavailable ]] () {}; + i (); // { dg-error "'foo\\\(bool, bool\\\)::' is unavailable" } + auto j = [][[gnu::unavailable]] {}; + j (); // { dg-error "'foo\\\(bool, bool\\\)::' is unavailable" } +#if __cpp_generic_lambdas >= 201304 + auto k = [] [[gnu::unavailable]] (auto x) {}; // { dg-bogus "is unavailable" } + k (0.0); // { dg-error "'foo\\\(bool, bool\\\)::\[^\n\r]*' is unavailable" "" { target c++14 } } +#endif +#if __cpp_generic_lambdas >= 201707 + auto l = [] [[gnu::unavailable]] (T) {}; // { dg-bogus "is unavailable" } + l (1); // { dg-error "'foo\\\(bool, bool\\\)::\[^\n\r]*' is unavailable" "" { target c++20 } } +#endif +}