summaryrefslogtreecommitdiff
path: root/clang/test/SemaCXX/copy-assignment.cpp
blob: 798582c149cf894818b98a216050f7c792d9dd43 (about) (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// RUN: %clang_cc1 -fsyntax-only -verify %s 
struct A {
};

struct ConvertibleToA {
  operator A();
};

struct ConvertibleToConstA {
  operator const A();
};

struct B {
  B& operator=(B&);  // expected-note 4 {{candidate function}}
};

struct ConvertibleToB {
  operator B();
};

struct ConvertibleToBref {
  operator B&();
};

struct ConvertibleToConstB {
  operator const B();
};

struct ConvertibleToConstBref {
  operator const B&();
};

struct C {
  int operator=(int); // expected-note{{candidate function}}
  long operator=(long); // expected-note{{candidate function}}
  int operator+=(int); // expected-note{{candidate function}}
  int operator+=(long); // expected-note{{candidate function}}
};

struct D {
  D& operator+=(const D &);
};

struct ConvertibleToInt {
  operator int();
};

void test() {
  A a, na;
  const A constA = A();
  ConvertibleToA convertibleToA;
  ConvertibleToConstA convertibleToConstA;

  B b, nb;
  const B constB = B();
  ConvertibleToB convertibleToB;
  ConvertibleToBref convertibleToBref;
  ConvertibleToConstB convertibleToConstB;
  ConvertibleToConstBref convertibleToConstBref;

  C c, nc;
  const C constC = C();

  D d, nd;
  const D constD = D();

  ConvertibleToInt convertibleToInt;

  na = a;
  na = constA;
  na = convertibleToA;
  na = convertibleToConstA;
  na += a; // expected-error{{no viable overloaded '+='}}

  nb = b;
  nb = constB;  // expected-error{{no viable overloaded '='}}
  nb = convertibleToB; // expected-error{{no viable overloaded '='}}
  nb = convertibleToBref;
  nb = convertibleToConstB; // expected-error{{no viable overloaded '='}}
  nb = convertibleToConstBref; // expected-error{{no viable overloaded '='}}

  nc = c;
  nc = constC;
  nc = 1;
  nc = 1L;
  nc = 1.0; // expected-error{{use of overloaded operator '=' is ambiguous}}
  nc += 1;
  nc += 1L;
  nc += 1.0; // expected-error{{use of overloaded operator '+=' is ambiguous}}

  nd = d;
  nd += d;
  nd += constD;

  int i;
  i = convertibleToInt;
  i = a; // expected-error{{assigning to 'int' from incompatible type 'A'}}
}

// <rdar://problem/8315440>: Don't crash
namespace test1 {
  template<typename T> class A : public unknown::X { // expected-error {{undeclared identifier 'unknown'}} expected-error {{expected class name}}
    A(UndeclaredType n) : X(n) {} // expected-error {{unknown type name 'UndeclaredType'}}
  };
  template<typename T> class B : public A<T>     {
    virtual void foo() {}
  };
  extern template class A<char>;
  extern template class B<char>;
}