Debian Codegraph @

gcc/testsuite/g++.dg/tc1/dr185.C

raw
1 // { dg-do run }
2 // Origin: Giovanni Bajo <giovannibajo at gcc dot gnu dot org>
3 // DR185: "Named" temporaries and copy elision
4
5 extern "C" void abort(void);
6
7 struct A {
8 mutable int value;
9 explicit A(int i) : value(i) {}
10 void mutate(int i) const { value = i; }
11 };
12
13 int foo() {
14 A const& t = A(1);
15 A n(t); // can this copy be elided? NO!
16 t.mutate(2);
17 return n.value; // can this return 2? NO!
18 }
19
20 int main()
21 {
22 int x = foo();
23 if (x != 1)
24 abort();
25 return 0;
26 }