public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-9965] c++: Don't emit deprecated warnings on lambda declarations
@ 2022-05-06 23:44 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2022-05-06 23:44 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:2fd2e6c1dffe305b10477b83a6c350a3f19e4058
commit r11-9965-g2fd2e6c1dffe305b10477b83a6c350a3f19e4058
Author: Jakub Jelinek <jakub@redhat.com>
Date: Wed May 4 10:07:36 2022 +0200
c++: Don't emit deprecated warnings on lambda declarations
On the following testcase, we emit deprecated warnings
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 <jakub@redhat.com>
* lambda.c: Include decl.h.
(maybe_add_lambda_conv_op): Temporarily override deprecated_state to
DEPRECATED_SUPPRESS.
* g++.dg/cpp23/lambda-attr1.C: New test.
(cherry picked from commit 1c8e9bed9b9d46d479b83ae05b334543f66961fb)
Diff:
---
gcc/cp/lambda.c | 11 ++++++++---
gcc/testsuite/g++.dg/cpp23/lambda-attr1.C | 29 +++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c
index d8efe91d9fe..cca414c1a69 100644
--- a/gcc/cp/lambda.c
+++ b/gcc/cp/lambda.c
@@ -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. */
@@ -1177,9 +1178,13 @@ maybe_add_lambda_conv_op (tree type)
}
}
else
- call = build_call_a (callop,
- direct_argvec->length (),
- direct_argvec->address ());
+ {
+ /* Don't warn on deprecated lambda declarations, unless
+ the lambda is actually called. */
+ auto du = make_temp_override (deprecated_state, 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..1528f734461
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp23/lambda-attr1.C
@@ -0,0 +1,29 @@
+// 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\\\)::<lambda\\\(\\\)>' is deprecated" }
+ auto d = [][[deprecated]] {}; // { dg-bogus "is deprecated" }
+ d (); // { dg-warning "'foo\\\(bool, bool\\\)::<lambda\\\(\\\)>' is deprecated" }
+#if __cpp_generic_lambdas >= 201304
+ auto e = [] [[deprecated]] (auto x) {}; // { dg-bogus "is deprecated" }
+ e (0.0); // { dg-warning "'foo\\\(bool, bool\\\)::<lambda\\\(auto:1\\\)>\[^\n\r]*' is deprecated" "" { target c++14 } }
+#endif
+#if __cpp_generic_lambdas >= 201707
+ auto f = [] <typename T> [[deprecated]] (T) {}; // { dg-bogus "is deprecated" }
+ f (1); // { dg-warning "'foo\\\(bool, bool\\\)::<lambda\\\(T\\\)>\[^\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\\\)::<lambda\\\(int\\\)>', declared with attribute 'nodiscard'" }
+ auto h = [] [[nodiscard]] { return 0; };
+ h (); // { dg-warning "ignoring return value of 'foo\\\(bool, bool\\\)::<lambda\\\(\\\)>', declared with attribute 'nodiscard'" }
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-05-06 23:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-06 23:44 [gcc r11-9965] c++: Don't emit deprecated warnings on lambda declarations Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).