aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-4.C
blob: 86db4e3c6c07c7821d7fd6b6e866eef06405cbdc (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
// Test how self-assignment detection handles constant-folding happening
// when parsing the RHS or the initializer.
// { dg-do compile }
// { dg-options "-Wself-assign -Wself-assign-non-pod" }

class Foo {
 private:
  int a_;

 public:
  Foo() : a_(a_+0) {} // should not warn

  void setA(int a) {
    a_ = a_ + 0; // should not warn
  }

  void operator=(Foo& rhs) {
    this->a_ = rhs.a_;
  }
};

struct Bar {
  int b_;
  float c_;
};

int g = g * 1; // should not warn

int func()
{
  Bar *bar1, bar2;
  Foo foo;
  int x = x - 0;        // should not warn
  static int y = y / 1; // should not warn
  float *f;
  Bar bar_array[5];

  *f = *f / 1;             // should not warn
  bar1->b_ = bar1->b_ * 1; // should not warn
  bar2.c_ = bar2.c_ - 0;   // should not warn
  foo.setA(5);
  bar_array[3].c_ = bar_array[3].c_ * 1;     // should not warn
  bar_array[x+g].b_ = bar_array[x+g].b_ / 1; // should not warn
  x += 0;
  y -= 0;
  foo = foo;           // { dg-warning "assigned to itself" }
  foo.operator=(foo);  // should not warn
}