xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/copy-constructor-error.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc struct S {
4*f4a2713aSLionel Sambuc    S (S);  // expected-error {{copy constructor must pass its first argument by reference}}
5*f4a2713aSLionel Sambuc };
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc S f();
8*f4a2713aSLionel Sambuc 
g()9*f4a2713aSLionel Sambuc void g() {
10*f4a2713aSLionel Sambuc   S a( f() );
11*f4a2713aSLionel Sambuc }
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc class foo {
14*f4a2713aSLionel Sambuc   foo(foo&, int); // expected-note {{previous}}
15*f4a2713aSLionel Sambuc   foo(int); // expected-note {{previous}}
16*f4a2713aSLionel Sambuc   foo(const foo&); // expected-note {{previous}}
17*f4a2713aSLionel Sambuc };
18*f4a2713aSLionel Sambuc 
foo(foo &,int=0)19*f4a2713aSLionel Sambuc foo::foo(foo&, int = 0) { } // expected-error {{makes this constructor a copy constructor}}
foo(int=0)20*f4a2713aSLionel Sambuc foo::foo(int = 0) { } // expected-error {{makes this constructor a default constructor}}
foo(const foo &=0)21*f4a2713aSLionel Sambuc foo::foo(const foo& = 0) { } //expected-error {{makes this constructor a default constructor}}
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc namespace PR6064 {
24*f4a2713aSLionel Sambuc   struct A {
APR6064::A25*f4a2713aSLionel Sambuc     A() { }
26*f4a2713aSLionel Sambuc     inline A(A&, int); // expected-note {{previous}}
27*f4a2713aSLionel Sambuc   };
28*f4a2713aSLionel Sambuc 
A(A &,int=0)29*f4a2713aSLionel Sambuc   A::A(A&, int = 0) { } // expected-error {{makes this constructor a copy constructor}}
30*f4a2713aSLionel Sambuc 
f()31*f4a2713aSLionel Sambuc   void f() {
32*f4a2713aSLionel Sambuc     A const a;
33*f4a2713aSLionel Sambuc     A b(a);
34*f4a2713aSLionel Sambuc   }
35*f4a2713aSLionel Sambuc }
36*f4a2713aSLionel Sambuc 
37*f4a2713aSLionel Sambuc namespace PR10618 {
38*f4a2713aSLionel Sambuc   struct A {
39*f4a2713aSLionel Sambuc     A(int, int, int); // expected-note {{previous}}
40*f4a2713aSLionel Sambuc   };
A(int a=0,int b=0,int c=0)41*f4a2713aSLionel Sambuc   A::A(int a = 0, // expected-error {{makes this constructor a default constructor}}
42*f4a2713aSLionel Sambuc        int b = 0,
43*f4a2713aSLionel Sambuc        int c = 0) {}
44*f4a2713aSLionel Sambuc 
45*f4a2713aSLionel Sambuc   struct B {
46*f4a2713aSLionel Sambuc     B(int);
47*f4a2713aSLionel Sambuc     B(const B&, int); // expected-note {{previous}}
48*f4a2713aSLionel Sambuc   };
B(const B &=B (0),int=0)49*f4a2713aSLionel Sambuc   B::B(const B& = B(0), // expected-error {{makes this constructor a default constructor}}
50*f4a2713aSLionel Sambuc        int = 0) {
51*f4a2713aSLionel Sambuc   }
52*f4a2713aSLionel Sambuc 
53*f4a2713aSLionel Sambuc   struct C {
54*f4a2713aSLionel Sambuc     C(const C&, int); // expected-note {{previous}}
55*f4a2713aSLionel Sambuc   };
C(const C &,int=0)56*f4a2713aSLionel Sambuc   C::C(const C&,
57*f4a2713aSLionel Sambuc        int = 0) { // expected-error {{makes this constructor a copy constructor}}
58*f4a2713aSLionel Sambuc   }
59*f4a2713aSLionel Sambuc }
60