Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 4fc526d | 2009-02-12 19:25:19 +0000 | [diff] [blame] | 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 | |
John McCall | 8120162 | 2010-01-08 04:41:39 +0000 | [diff] [blame] | 40 | double promote(float) __attribute__((__overloadable__)); // expected-note {{candidate}} |
| 41 | double promote(double) __attribute__((__overloadable__)); // expected-note {{candidate}} |
| 42 | long double promote(long double) __attribute__((__overloadable__)); // expected-note {{candidate}} |
Douglas Gregor | c6666f8 | 2009-02-18 06:34:51 +0000 | [diff] [blame] | 43 | |
Douglas Gregor | 965acbb | 2009-02-18 07:07:28 +0000 | [diff] [blame] | 44 | void promote(...) __attribute__((__overloadable__, __unavailable__)); // \ |
Douglas Gregor | 48f3bb9 | 2009-02-18 21:56:37 +0000 | [diff] [blame] | 45 | // expected-note{{candidate function}} |
Douglas Gregor | c6666f8 | 2009-02-18 06:34:51 +0000 | [diff] [blame] | 46 | |
| 47 | void test_promote(short* sp) { |
| 48 | promote(1.0); |
Douglas Gregor | 48f3bb9 | 2009-02-18 21:56:37 +0000 | [diff] [blame] | 49 | promote(sp); // expected-error{{call to unavailable function 'promote'}} |
Douglas Gregor | c6666f8 | 2009-02-18 06:34:51 +0000 | [diff] [blame] | 50 | } |
| 51 | |
John McCall | 1c471f3 | 2010-03-12 23:14:13 +0000 | [diff] [blame] | 52 | // PR6600 |
| 53 | typedef double Double; |
| 54 | typedef Double DoubleVec __attribute__((vector_size(16))); |
| 55 | typedef int Int; |
| 56 | typedef Int IntVec __attribute__((vector_size(16))); |
| 57 | double magnitude(DoubleVec) __attribute__((__overloadable__)); |
| 58 | double magnitude(IntVec) __attribute__((__overloadable__)); |
| 59 | double test_p6600(DoubleVec d) { |
| 60 | return magnitude(d) * magnitude(d); |
| 61 | } |
Douglas Gregor | d945538 | 2010-08-06 13:50:58 +0000 | [diff] [blame] | 62 | |
| 63 | // PR7738 |
| 64 | extern int __attribute__((overloadable)) f0(); // expected-error{{'overloadable' function 'f0' must have a prototype}} |
| 65 | typedef int f1_type(); |
| 66 | f1_type __attribute__((overloadable)) f1; // expected-error{{'overloadable' function 'f1' must have a prototype}} |
| 67 | |
| 68 | void test() { |
| 69 | f0(); |
| 70 | f1(); |
| 71 | } |