Home | History | Annotate | Download | only in Sema
      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 
      5 int *f(int) __attribute__((overloadable)); // expected-note 2{{previous overload of function is here}}
      6 float *f(float); // expected-error{{overloaded function 'f' must have the 'overloadable' attribute}}
      7 int *f(int); // expected-error{{redeclaration of 'f' must have the 'overloadable' attribute}} \
      8              // expected-note{{previous declaration is here}}
      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; };
     30 int* accept_struct(struct X x) __attribute__((__overloadable__));
     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'}}
     39 
     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}}
     43 
     44 void promote(...) __attribute__((__overloadable__, __unavailable__)); // \
     45     // expected-note{{candidate function}}
     46 
     47 void test_promote(short* sp) {
     48   promote(1.0);
     49   promote(sp); // expected-error{{call to unavailable function 'promote'}}
     50 }
     51 
     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 }
     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 }
     72