aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp23/elision7.C
blob: 0045842b34fb18ecc865efd8078c0c7139f43609 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// PR c++/101165 - P2266R1 - Simpler implicit move
// { dg-do compile { target c++23 } }
// { dg-options "-Wdangling-reference" }

struct X {
  X ();
  X(X&&);
};

X&& rref ();

X&&
f1 (X&& x)
{
  return x;
}

template<typename T> T&&
f2 (T&& x)
{
  return x;
}
template X& f2<X&>(X&);
template X&& f2<X>(X&&);

X&&
f3 ()
{
  X&& x = rref ();
  return x;
}

void
f4 ()
try {
  X x;
  throw x;
} catch (...) { }

void
f5 ()
{
  auto l1 = [](auto x) -> auto { return x; };
  auto &&x1 = l1(X{});
  auto l2 = [](auto x) -> auto& { return x; }; // { dg-error "cannot bind non-const lvalue reference" }
  auto &&x2 = l2(X{});
  auto l3 = [](auto x) -> auto&& { return x; }; // { dg-warning "reference to local" }
  auto &&x3 = l3(X{});
}

constexpr int &
f6 (int &&n)
{
  return n; // { dg-error "cannot bind non-const lvalue reference" }
}

void
do_f6 ()
{
  auto x = f6 (42);
}

template<typename T> auto &
f7 (T &&t)
{
  return t; // { dg-error "cannot bind non-const lvalue reference" }
}

void
do_f7 ()
{
  const int &x = f7 (0); // { dg-warning "dangling reference" }
}