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