aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/lambda.cc12
-rw-r--r--gcc/testsuite/g++.dg/cpp23/lambda-attr1.C37
-rw-r--r--gcc/testsuite/g++.dg/cpp23/lambda-attr2.C19
3 files changed, 65 insertions, 3 deletions
diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc
index 10834d6..afac53b 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 0000000..a653c73
--- /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\\\)::<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'" }
+ 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 = [] <typename T> [[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 0000000..0392b17
--- /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\\\)::<lambda\\\(\\\)>' is unavailable" }
+ auto j = [][[gnu::unavailable]] {};
+ j (); // { dg-error "'foo\\\(bool, bool\\\)::<lambda\\\(\\\)>' 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\\\)::<lambda\\\(auto:1\\\)>\[^\n\r]*' is unavailable" "" { target c++14 } }
+#endif
+#if __cpp_generic_lambdas >= 201707
+ auto l = [] <typename T> [[gnu::unavailable]] (T) {}; // { dg-bogus "is unavailable" }
+ l (1); // { dg-error "'foo\\\(bool, bool\\\)::<lambda\\\(T\\\)>\[^\n\r]*' is unavailable" "" { target c++20 } }
+#endif
+}