aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp23/lambda-attr1.C
blob: a653c732fca44972e9a48d8d5bee0c0d1d2061d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
}