xref: /aosp_15_r20/external/clang/test/SemaCXX/function-pointer-arguments.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li //RUN: %clang_cc1 -fsyntax-only -verify %s
2*67e74705SXin Li 
3*67e74705SXin Li namespace PR16570 {
4*67e74705SXin Li   int f1(int, int);
5*67e74705SXin Li   int f2(const int, int);
6*67e74705SXin Li   int f3(int&, int);
7*67e74705SXin Li   int f4(const int&, int);
8*67e74705SXin Li 
good()9*67e74705SXin Li   void good() {
10*67e74705SXin Li     int(*g1)(int, int) = f1;
11*67e74705SXin Li     int(*g2)(const int, int) = f1;
12*67e74705SXin Li     int(*g3)(volatile int, int) = f1;
13*67e74705SXin Li     int(*g4)(int, int) = f2;
14*67e74705SXin Li     int(*g5)(const int, int) = f2;
15*67e74705SXin Li     int(*g6)(volatile int, int) = f2;
16*67e74705SXin Li     int(*g7)(int&, int) = f3;
17*67e74705SXin Li     int(*g8)(const int&, int) = f4;
18*67e74705SXin Li   }
19*67e74705SXin Li 
bad()20*67e74705SXin Li   void bad() {
21*67e74705SXin Li     void (*g1)(int, int) = f1;
22*67e74705SXin Li     // expected-error@-1 {{different return type ('void' vs 'int'}}
23*67e74705SXin Li     const int (*g2)(int, int) = f1;
24*67e74705SXin Li     // expected-error@-1 {{different return type ('const int' vs 'int')}}
25*67e74705SXin Li 
26*67e74705SXin Li     int (*g3)(char, int) = f1;
27*67e74705SXin Li     // expected-error@-1 {{type mismatch at 1st parameter ('char' vs 'int')}}
28*67e74705SXin Li     int (*g4)(int, char) = f1;
29*67e74705SXin Li     // expected-error@-1 {{type mismatch at 2nd parameter ('char' vs 'int')}}
30*67e74705SXin Li 
31*67e74705SXin Li     int (*g5)(int) = f1;
32*67e74705SXin Li     // expected-error@-1 {{different number of parameters (1 vs 2)}}
33*67e74705SXin Li 
34*67e74705SXin Li     int (*g6)(int, int, int) = f1;
35*67e74705SXin Li     // expected-error@-1 {{different number of parameters (3 vs 2)}}
36*67e74705SXin Li 
37*67e74705SXin Li     int (*g7)(const int, char) = f1;
38*67e74705SXin Li     // expected-error@-1 {{type mismatch at 2nd parameter ('char' vs 'int')}}
39*67e74705SXin Li     int (*g8)(int, char) = f2;
40*67e74705SXin Li     // expected-error@-1 {{type mismatch at 2nd parameter ('char' vs 'int')}}
41*67e74705SXin Li     int (*g9)(const int&, char) = f3;
42*67e74705SXin Li     // expected-error@-1 {{type mismatch at 1st parameter ('const int &' vs 'int &')}}
43*67e74705SXin Li     int (*g10)(int&, char) = f4;
44*67e74705SXin Li     // expected-error@-1 {{type mismatch at 1st parameter ('int &' vs 'const int &')}}
45*67e74705SXin Li   }
46*67e74705SXin Li 
47*67e74705SXin Li   typedef void (*F)(const char * __restrict__, int);
48*67e74705SXin Li   void g(const char *, unsigned);
49*67e74705SXin Li   F f = g;
50*67e74705SXin Li   // expected-error@-1 {{type mismatch at 2nd parameter ('int' vs 'unsigned int')}}
51*67e74705SXin Li 
52*67e74705SXin Li }
53