blob: d4cb92c334169489eeddd384ee44d74e9a08e54f (
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
|
// PR c++/25979
// Bug: we were eliding too many temporaries, so that a1 was used
// as both 'a' and 'x' in the second operator+.
// { dg-do run }
struct A
{
A() : data1_(0), data2_(0) {}
A(int i, int j) : data1_(i), data2_(j) {}
A operator+(int);
friend A operator+(int, const A&);
~A() {}
//private:
int data1_;
int data2_;
};
extern bool x;
extern "C" void abort ();
int main()
{
A a1(1,2);
a1 = (x ? a1 + 3 : 3 + a1);
if (a1.data1_ != 3 || a1.data2_ != 2)
abort ();
}
bool x = false;
A
A::operator+(int i)
{
A a;
a = *this;
a.data2_ = i;
return a;
}
A
operator+(int i, const A& x)
{
A a;
a = x;
a.data1_ = i;
return a;
}
|