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