xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/copy-ctor-assign.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // Make sure that copy constructors and assignment operators are properly
4*f4a2713aSLionel Sambuc // generated when there is a matching
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc // PR5072
7*f4a2713aSLionel Sambuc template<typename T>
8*f4a2713aSLionel Sambuc struct X {
9*f4a2713aSLionel Sambuc   template<typename U>
XX10*f4a2713aSLionel Sambuc   X(const X<U>& other)
11*f4a2713aSLionel Sambuc     : value(other.value + 1) { } // expected-error{{binary expression}}
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc   template<typename U>
operator =X14*f4a2713aSLionel Sambuc   X& operator=(const X<U>& other)  {
15*f4a2713aSLionel Sambuc     value = other.value + 1; // expected-error{{binary expression}}
16*f4a2713aSLionel Sambuc     return *this;
17*f4a2713aSLionel Sambuc   }
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc   T value;
20*f4a2713aSLionel Sambuc };
21*f4a2713aSLionel Sambuc 
22*f4a2713aSLionel Sambuc struct Y {};
23*f4a2713aSLionel Sambuc 
test0(X<int Y::* > x)24*f4a2713aSLionel Sambuc X<int Y::*> test0(X<int Y::*> x) { return x; }
test1(X<long> x)25*f4a2713aSLionel Sambuc X<int> test1(X<long> x) { return x; }
26*f4a2713aSLionel Sambuc 
27*f4a2713aSLionel Sambuc 
test2(X<int Y::* > x)28*f4a2713aSLionel Sambuc X<int> test2(X<int Y::*> x) {
29*f4a2713aSLionel Sambuc   return x; // expected-note{{instantiation}}
30*f4a2713aSLionel Sambuc }
31*f4a2713aSLionel Sambuc 
test3(X<int> & x,X<int> xi,X<long> xl,X<int Y::* > xmptr)32*f4a2713aSLionel Sambuc void test3(X<int> &x, X<int> xi, X<long> xl, X<int Y::*> xmptr) {
33*f4a2713aSLionel Sambuc   x = xi;
34*f4a2713aSLionel Sambuc   x = xl;
35*f4a2713aSLionel Sambuc   x = xmptr; // expected-note{{instantiation}}
36*f4a2713aSLionel Sambuc }
37*f4a2713aSLionel Sambuc 
38*f4a2713aSLionel Sambuc struct X1 {
39*f4a2713aSLionel Sambuc   X1 &operator=(const X1&);
40*f4a2713aSLionel Sambuc };
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc template<typename T>
43*f4a2713aSLionel Sambuc struct X2 : X1 {
44*f4a2713aSLionel Sambuc   template<typename U> X2 &operator=(const U&);
45*f4a2713aSLionel Sambuc };
46*f4a2713aSLionel Sambuc 
47*f4a2713aSLionel Sambuc struct X3 : X2<int> {
48*f4a2713aSLionel Sambuc };
49*f4a2713aSLionel Sambuc 
test_X2(X3 & to,X3 from)50*f4a2713aSLionel Sambuc void test_X2(X3 &to, X3 from) {
51*f4a2713aSLionel Sambuc   to = from;
52*f4a2713aSLionel Sambuc }
53