aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-3.C
blob: 4c37f5764d4e0f7bb9af69f95e513586ae02df5b (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
// Test how operands_equal_p handles a NULL operand.
// { dg-do compile }
// { dg-options "-Wself-assign  -Wself-assign-non-pod" }

#include <cstdio>

namespace testing {

class Foo {
  int f;
 public:
  Foo() { printf("Construct Foo\n"); }
};

class Bar {
  int b;
 public:
  Bar(int x) { printf("Construct Bar\n"); }

  void operator=(const Foo& foo) {
    printf("Assign Foo to Bar\n");
  }
};

}

template <class T>
void func(T t) {
  ::testing::Bar(1) = ::testing::Foo(); // used to trigger a segfault
  ::testing::Foo() = ::testing::Foo(); // { dg-warning "assigned to itself" }
}

main() {
  func(2);
}