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