aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/warn/Wself-assign-3.C
blob: bc5732de91d99e9b19ffea9f639490e5c9b416e4 (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" }

#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();
}

main() {
  func(2);
}