blob: 0d5db3a98454833ebf683ae0e7b8b8dc7427edd5 [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -verify %s
Douglas Gregor4fc526d2009-02-12 19:25:19 +00002
3int var __attribute__((overloadable)); // expected-error{{'overloadable' attribute can only be applied to a function}}
4
Douglas Gregorae170942009-02-13 00:26:38 +00005int *f(int) __attribute__((overloadable)); // expected-note 2{{previous overload of function is here}}
Douglas Gregor4fc526d2009-02-12 19:25:19 +00006float *f(float); // expected-error{{overloaded function 'f' must have the 'overloadable' attribute}}
Douglas Gregorae170942009-02-13 00:26:38 +00007int *f(int); // expected-error{{redeclaration of 'f' must have the 'overloadable' attribute}} \
8 // expected-note{{previous declaration is here}}
Douglas Gregor4fc526d2009-02-12 19:25:19 +00009double *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'; candidates are:}}
26}
27
28struct X { int x; float y; };
29struct Y { int x; float y; };
Douglas Gregor28465842009-02-17 18:51:14 +000030int* accept_struct(struct X x) __attribute__((__overloadable__));
Douglas Gregor4fc526d2009-02-12 19:25:19 +000031float* 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'}}
Douglas Gregorae170942009-02-13 00:26:38 +000039
Douglas Gregorc6666f82009-02-18 06:34:51 +000040double promote(float) __attribute__((__overloadable__));
41double promote(double) __attribute__((__overloadable__));
42long double promote(long double) __attribute__((__overloadable__));
43
44void promote() __attribute__((__overloadable__)); // expected-error{{'overloadable' function 'promote' must have a prototype}}
Douglas Gregor965acbb2009-02-18 07:07:28 +000045void promote(...) __attribute__((__overloadable__, __unavailable__)); // \
Douglas Gregor48f3bb92009-02-18 21:56:37 +000046 // expected-note{{candidate function}}
Douglas Gregorc6666f82009-02-18 06:34:51 +000047
48void test_promote(short* sp) {
49 promote(1.0);
Douglas Gregor48f3bb92009-02-18 21:56:37 +000050 promote(sp); // expected-error{{call to unavailable function 'promote'}}
Douglas Gregorc6666f82009-02-18 06:34:51 +000051}
52
Douglas Gregorae170942009-02-13 00:26:38 +000053