aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-5.C
blob: 898ddecd7116b10116034b11339171fbc35ca022 (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
// Test -Wself-assign and -Wself-assign-non-pod.
// { dg-do compile }
// { dg-options "-Wself-assign -Wself-assign-non-pod" }

template<typename T>
class Foo {
 private:
  T a_;
 public:
  Foo() : a_(a_) {}        // { dg-warning "assigned to itself" }
  void Set() { a_ = a_; }  // { dg-warning "assigned to itself" }
};

struct Bar {
  int b_;
  int c_;
  void operator=(Bar& rhs) {
    this->b_ = rhs.b_;
    this->c_ = rhs.c_;
  }
};

template <typename T>
void func() {
  T a;
  a = a;  // { dg-warning "assigned to itself" }
}

main()
{
  Foo<Bar> foo;
  Bar *bar1, bar2;
  func<int>();
  foo = foo;          // { dg-warning "assigned to itself" }
  bar2 = bar2;        // { dg-warning "assigned to itself" }
  bar1 = bar1;        // { dg-warning "assigned to itself" }
  bar2.b_ = bar2.b_;  // { dg-warning "assigned to itself" }
}