Debian Codegraph @

gcc/testsuite/g++.dg/ext/attr-no-dangling7.C

raw
1 // PR c++/110358
2 // { dg-do compile { target c++20 } }
3 // { dg-options "-Wdangling-reference" }
4
5 class X { int i; };
6 const X x1 {};
7 const X x2 {};
8
9 template<bool... N>
10 [[gnu::no_dangling(N)]] const X& get(const int& i); // { dg-error "parameter packs not expanded" }
11
12 template<typename T>
13 [[gnu::no_dangling(T::x)]] // { dg-error "member" }
14 const X& foo(const int& i);
15
16 bool val () { return true; }
17
18 [[gnu::no_dangling(val ())]] // { dg-error "call" }
19 const X& bar (const int& i, const X&);
20
21 [[gnu::no_dangling(20)]] const X& fn1 (const int &, const X&);
22
23 void
24 test ()
25 {
26 [[maybe_unused]] const X& x1 = bar (10, X{}); // { dg-warning "dangling" }
27 [[maybe_unused]] const X& x2 = foo<int> (10); // { dg-error "no matching" }
28 [[maybe_unused]] const X& x3 // { dg-warning "dangling" }
29 = fn1 (10, X{}); // { dg-error "narrowing" }
30 }
31