xref: /aosp_15_r20/external/clang/test/SemaCXX/overload-decl.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s
2*67e74705SXin Li void f();
3*67e74705SXin Li void f(int);
4*67e74705SXin Li void f(int, float);
5*67e74705SXin Li void f(int, int);
6*67e74705SXin Li void f(int, ...);
7*67e74705SXin Li 
8*67e74705SXin Li typedef float Float;
9*67e74705SXin Li void f(int, Float); // expected-note {{previous declaration is here}}
10*67e74705SXin Li 
11*67e74705SXin Li int f(int, Float); // expected-error {{functions that differ only in their return type cannot be overloaded}}
12*67e74705SXin Li 
13*67e74705SXin Li void g(void); // expected-note {{previous declaration is here}}
14*67e74705SXin Li int g(); // expected-error {{functions that differ only in their return type cannot be overloaded}}
15*67e74705SXin Li 
16*67e74705SXin Li typedef int INT;
17*67e74705SXin Li 
18*67e74705SXin Li class X {
19*67e74705SXin Li   void f();
20*67e74705SXin Li   void f(int); // expected-note {{previous declaration is here}}
21*67e74705SXin Li   void f() const;
22*67e74705SXin Li 
23*67e74705SXin Li   void f(INT); // expected-error{{cannot be redeclared}}
24*67e74705SXin Li 
25*67e74705SXin Li   void g(int); // expected-note {{previous declaration is here}}
26*67e74705SXin Li   void g(int, float); // expected-note {{previous declaration is here}}
27*67e74705SXin Li   int g(int, Float); // expected-error {{functions that differ only in their return type cannot be overloaded}}
28*67e74705SXin Li 
29*67e74705SXin Li   static void g(float); // expected-note {{previous declaration is here}}
30*67e74705SXin Li   static void g(int); // expected-error {{static and non-static member functions with the same parameter types cannot be overloaded}}
31*67e74705SXin Li   static void g(float); // expected-error {{class member cannot be redeclared}}
32*67e74705SXin Li 
33*67e74705SXin Li   void h(); // expected-note {{previous declaration is here}}
34*67e74705SXin Li   void h() __restrict; // expected-error {{class member cannot be redeclared}}
35*67e74705SXin Li };
36*67e74705SXin Li 
main()37*67e74705SXin Li int main() {} // expected-note {{previous definition is here}}
main(int,char **)38*67e74705SXin Li int main(int,char**) {} // expected-error {{conflicting types for 'main'}}
39