Douglas Gregor | 4fc526d | 2009-02-12 19:25:19 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify %s |
| 2 | |
| 3 | int var __attribute__((overloadable)); // expected-error{{'overloadable' attribute can only be applied to a function}} |
| 4 | |
Douglas Gregor | ae17094 | 2009-02-13 00:26:38 +0000 | [diff] [blame] | 5 | int *f(int) __attribute__((overloadable)); // expected-note 2{{previous overload of function is here}} |
Douglas Gregor | 4fc526d | 2009-02-12 19:25:19 +0000 | [diff] [blame] | 6 | float *f(float); // expected-error{{overloaded function 'f' must have the 'overloadable' attribute}} |
Douglas Gregor | ae17094 | 2009-02-13 00:26:38 +0000 | [diff] [blame] | 7 | int *f(int); // expected-error{{redeclaration of 'f' must have the 'overloadable' attribute}} \ |
| 8 | // expected-note{{previous declaration is here}} |
Douglas Gregor | 4fc526d | 2009-02-12 19:25:19 +0000 | [diff] [blame] | 9 | double *f(double) __attribute__((overloadable)); // okay, new |
| 10 | |
| 11 | void 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 | |
| 17 | int *accept_funcptr(int (*)()) __attribute__((overloadable)); // \ |
| 18 | // expected-note{{candidate function}} |
| 19 | float *accept_funcptr(int (*)(int, double)) __attribute__((overloadable)); // \ |
| 20 | // expected-note{{candidate function}} |
| 21 | |
| 22 | void 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 | |
| 28 | struct X { int x; float y; }; |
| 29 | struct Y { int x; float y; }; |
Douglas Gregor | 2846584 | 2009-02-17 18:51:14 +0000 | [diff] [blame] | 30 | int* accept_struct(struct X x) __attribute__((__overloadable__)); |
Douglas Gregor | 4fc526d | 2009-02-12 19:25:19 +0000 | [diff] [blame] | 31 | float* accept_struct(struct Y y) __attribute__((overloadable)); |
| 32 | |
| 33 | void test_struct(struct X x, struct Y y) { |
| 34 | int *ip = accept_struct(x); |
| 35 | float *fp = accept_struct(y); |
| 36 | } |
| 37 | |
| 38 | double *f(int) __attribute__((overloadable)); // expected-error{{conflicting types for 'f'}} |
Douglas Gregor | ae17094 | 2009-02-13 00:26:38 +0000 | [diff] [blame] | 39 | |
Douglas Gregor | c6666f8 | 2009-02-18 06:34:51 +0000 | [diff] [blame] | 40 | double promote(float) __attribute__((__overloadable__)); |
| 41 | double promote(double) __attribute__((__overloadable__)); |
| 42 | long double promote(long double) __attribute__((__overloadable__)); |
| 43 | |
| 44 | void promote() __attribute__((__overloadable__)); // expected-error{{'overloadable' function 'promote' must have a prototype}} |
Douglas Gregor | 965acbb | 2009-02-18 07:07:28 +0000 | [diff] [blame^] | 45 | void promote(...) __attribute__((__overloadable__, __unavailable__)); // \ |
| 46 | // expected-note{{unavailable function is declared here}} |
Douglas Gregor | c6666f8 | 2009-02-18 06:34:51 +0000 | [diff] [blame] | 47 | |
| 48 | void test_promote(short* sp) { |
| 49 | promote(1.0); |
Douglas Gregor | 965acbb | 2009-02-18 07:07:28 +0000 | [diff] [blame^] | 50 | promote(sp); // expected-error{{call to function 'promote' that has been intentionally made unavailable}} |
Douglas Gregor | c6666f8 | 2009-02-18 06:34:51 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Douglas Gregor | ae17094 | 2009-02-13 00:26:38 +0000 | [diff] [blame] | 53 | |