xref: /aosp_15_r20/external/clang/test/SemaCXX/constructor.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s
2*67e74705SXin Li typedef int INT;
3*67e74705SXin Li 
4*67e74705SXin Li class Foo {
5*67e74705SXin Li   Foo();
6*67e74705SXin Li   (Foo)(float) { }
7*67e74705SXin Li   explicit Foo(int); // expected-note {{previous declaration is here}}
8*67e74705SXin Li   Foo(const Foo&);
9*67e74705SXin Li 
10*67e74705SXin Li   ((Foo))(INT); // expected-error{{cannot be redeclared}}
11*67e74705SXin Li 
12*67e74705SXin Li   Foo(Foo foo, int i = 17, int j = 42); // expected-error{{copy constructor must pass its first argument by reference}}
13*67e74705SXin Li 
14*67e74705SXin Li   static Foo(short, short); // expected-error{{constructor cannot be declared 'static'}}
15*67e74705SXin Li   virtual Foo(double); // expected-error{{constructor cannot be declared 'virtual'}}
16*67e74705SXin Li   Foo(long) const; // expected-error{{'const' qualifier is not allowed on a constructor}}
17*67e74705SXin Li 
18*67e74705SXin Li   int Foo(int, int); // expected-error{{constructor cannot have a return type}}
19*67e74705SXin Li 
20*67e74705SXin Li   volatile Foo(float); // expected-error{{constructor cannot have a return type}}
21*67e74705SXin Li };
22*67e74705SXin Li 
Foo(const Foo &)23*67e74705SXin Li Foo::Foo(const Foo&) { }
24*67e74705SXin Li 
25*67e74705SXin Li typedef struct {
26*67e74705SXin Li   int version;
27*67e74705SXin Li } Anon;
28*67e74705SXin Li extern const Anon anon;
29*67e74705SXin Li extern "C" const Anon anon2;
30*67e74705SXin Li 
31*67e74705SXin Li // PR3188: The extern declaration complained about not having an appropriate
32*67e74705SXin Li // constructor.
33*67e74705SXin Li struct x;
34*67e74705SXin Li extern x a;
35*67e74705SXin Li 
36*67e74705SXin Li // A similar case.
37*67e74705SXin Li struct y {
38*67e74705SXin Li   y(int);
39*67e74705SXin Li };
40*67e74705SXin Li extern y b;
41*67e74705SXin Li 
42*67e74705SXin Li struct Length {
lLength43*67e74705SXin Li   Length l() const { return *this; }
44*67e74705SXin Li };
45*67e74705SXin Li 
46*67e74705SXin Li // <rdar://problem/6815988>
47*67e74705SXin Li struct mmst_reg{
48*67e74705SXin Li  char mmst_reg[10];
49*67e74705SXin Li };
50*67e74705SXin Li 
51*67e74705SXin Li // PR3948
52*67e74705SXin Li namespace PR3948 {
53*67e74705SXin Li // PR3948
54*67e74705SXin Li class a {
55*67e74705SXin Li   public:
56*67e74705SXin Li   int b(int a());
57*67e74705SXin Li };
58*67e74705SXin Li int x();
y()59*67e74705SXin Li void y() {
60*67e74705SXin Li   a z; z.b(x);
61*67e74705SXin Li }
62*67e74705SXin Li }
63*67e74705SXin Li 
64*67e74705SXin Li namespace A {
65*67e74705SXin Li   struct S {
66*67e74705SXin Li     S();
67*67e74705SXin Li     S(int);
68*67e74705SXin Li     void f1();
69*67e74705SXin Li     void f2();
70*67e74705SXin Li     operator int ();
71*67e74705SXin Li     ~S();
72*67e74705SXin Li   };
73*67e74705SXin Li }
74*67e74705SXin Li 
S()75*67e74705SXin Li A::S::S() {}
76*67e74705SXin Li 
f1()77*67e74705SXin Li void A::S::f1() {}
78*67e74705SXin Li 
79*67e74705SXin Li struct S {};
80*67e74705SXin Li 
S(int)81*67e74705SXin Li A::S::S(int) {}
82*67e74705SXin Li 
f2()83*67e74705SXin Li void A::S::f2() {}
84*67e74705SXin Li 
operator int()85*67e74705SXin Li A::S::operator int() { return 1; }
86*67e74705SXin Li 
~S()87*67e74705SXin Li A::S::~S() {}
88*67e74705SXin Li 
89