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