xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/overloadable.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc int var __attribute__((overloadable)); // expected-error{{'overloadable' attribute can only be applied to a function}}
4*f4a2713aSLionel Sambuc void params(void) __attribute__((overloadable(12))); // expected-error {{'overloadable' attribute takes no arguments}}
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc int *f(int) __attribute__((overloadable)); // expected-note 2{{previous overload of function is here}}
7*f4a2713aSLionel Sambuc float *f(float); // expected-error{{overloaded function 'f' must have the 'overloadable' attribute}}
8*f4a2713aSLionel Sambuc int *f(int); // expected-error{{redeclaration of 'f' must have the 'overloadable' attribute}} \
9*f4a2713aSLionel Sambuc              // expected-note{{previous declaration is here}}
10*f4a2713aSLionel Sambuc double *f(double) __attribute__((overloadable)); // okay, new
11*f4a2713aSLionel Sambuc 
12*f4a2713aSLionel Sambuc void test_f(int iv, float fv, double dv) {
13*f4a2713aSLionel Sambuc   int *ip = f(iv);
14*f4a2713aSLionel Sambuc   float *fp = f(fv);
15*f4a2713aSLionel Sambuc   double *dp = f(dv);
16*f4a2713aSLionel Sambuc }
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc int *accept_funcptr(int (*)()) __attribute__((overloadable)); //         \
19*f4a2713aSLionel Sambuc   // expected-note{{candidate function}}
20*f4a2713aSLionel Sambuc float *accept_funcptr(int (*)(int, double)) __attribute__((overloadable)); //  \
21*f4a2713aSLionel Sambuc   // expected-note{{candidate function}}
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc void test_funcptr(int (*f1)(int, double),
24*f4a2713aSLionel Sambuc                   int (*f2)(int, float)) {
25*f4a2713aSLionel Sambuc   float *fp = accept_funcptr(f1);
26*f4a2713aSLionel Sambuc   accept_funcptr(f2); // expected-error{{no matching function for call to 'accept_funcptr'}}
27*f4a2713aSLionel Sambuc }
28*f4a2713aSLionel Sambuc 
29*f4a2713aSLionel Sambuc struct X { int x; float y; };
30*f4a2713aSLionel Sambuc struct Y { int x; float y; };
31*f4a2713aSLionel Sambuc int* accept_struct(struct X x) __attribute__((__overloadable__));
32*f4a2713aSLionel Sambuc float* accept_struct(struct Y y) __attribute__((overloadable));
33*f4a2713aSLionel Sambuc 
34*f4a2713aSLionel Sambuc void test_struct(struct X x, struct Y y) {
35*f4a2713aSLionel Sambuc   int *ip = accept_struct(x);
36*f4a2713aSLionel Sambuc   float *fp = accept_struct(y);
37*f4a2713aSLionel Sambuc }
38*f4a2713aSLionel Sambuc 
39*f4a2713aSLionel Sambuc double *f(int) __attribute__((overloadable)); // expected-error{{conflicting types for 'f'}}
40*f4a2713aSLionel Sambuc 
41*f4a2713aSLionel Sambuc double promote(float) __attribute__((__overloadable__)); // expected-note {{candidate}}
42*f4a2713aSLionel Sambuc double promote(double) __attribute__((__overloadable__)); // expected-note {{candidate}}
43*f4a2713aSLionel Sambuc long double promote(long double) __attribute__((__overloadable__)); // expected-note {{candidate}}
44*f4a2713aSLionel Sambuc 
45*f4a2713aSLionel Sambuc void promote(...) __attribute__((__overloadable__, __unavailable__)); // \
46*f4a2713aSLionel Sambuc     // expected-note{{candidate function}}
47*f4a2713aSLionel Sambuc 
48*f4a2713aSLionel Sambuc void test_promote(short* sp) {
49*f4a2713aSLionel Sambuc   promote(1.0);
50*f4a2713aSLionel Sambuc   promote(sp); // expected-error{{call to unavailable function 'promote'}}
51*f4a2713aSLionel Sambuc }
52*f4a2713aSLionel Sambuc 
53*f4a2713aSLionel Sambuc // PR6600
54*f4a2713aSLionel Sambuc typedef double Double;
55*f4a2713aSLionel Sambuc typedef Double DoubleVec __attribute__((vector_size(16)));
56*f4a2713aSLionel Sambuc typedef int Int;
57*f4a2713aSLionel Sambuc typedef Int IntVec __attribute__((vector_size(16)));
58*f4a2713aSLionel Sambuc double magnitude(DoubleVec) __attribute__((__overloadable__));
59*f4a2713aSLionel Sambuc double magnitude(IntVec) __attribute__((__overloadable__));
60*f4a2713aSLionel Sambuc double test_p6600(DoubleVec d) {
61*f4a2713aSLionel Sambuc   return magnitude(d) * magnitude(d);
62*f4a2713aSLionel Sambuc }
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc // PR7738
65*f4a2713aSLionel Sambuc extern int __attribute__((overloadable)) f0(); // expected-error{{'overloadable' function 'f0' must have a prototype}}
66*f4a2713aSLionel Sambuc typedef int f1_type();
67*f4a2713aSLionel Sambuc f1_type __attribute__((overloadable)) f1; // expected-error{{'overloadable' function 'f1' must have a prototype}}
68*f4a2713aSLionel Sambuc 
69*f4a2713aSLionel Sambuc void test() {
70*f4a2713aSLionel Sambuc   f0();
71*f4a2713aSLionel Sambuc   f1();
72*f4a2713aSLionel Sambuc }
73*f4a2713aSLionel Sambuc 
74*f4a2713aSLionel Sambuc void before_local_1(int) __attribute__((overloadable)); // expected-note {{here}}
75*f4a2713aSLionel Sambuc void before_local_2(int); // expected-note {{here}}
76*f4a2713aSLionel Sambuc void before_local_3(int) __attribute__((overloadable));
77*f4a2713aSLionel Sambuc void local() {
78*f4a2713aSLionel Sambuc   void before_local_1(char); // expected-error {{must have the 'overloadable' attribute}}
79*f4a2713aSLionel Sambuc   void before_local_2(char) __attribute__((overloadable)); // expected-error {{conflicting types}}
80*f4a2713aSLionel Sambuc   void before_local_3(char) __attribute__((overloadable));
81*f4a2713aSLionel Sambuc   void after_local_1(char); // expected-note {{here}}
82*f4a2713aSLionel Sambuc   void after_local_2(char) __attribute__((overloadable)); // expected-note {{here}}
83*f4a2713aSLionel Sambuc   void after_local_3(char) __attribute__((overloadable));
84*f4a2713aSLionel Sambuc }
85*f4a2713aSLionel Sambuc void after_local_1(int) __attribute__((overloadable)); // expected-error {{conflicting types}}
86*f4a2713aSLionel Sambuc void after_local_2(int); // expected-error {{must have the 'overloadable' attribute}}
87*f4a2713aSLionel Sambuc void after_local_3(int) __attribute__((overloadable));
88