overloadable.c 3.6 KB

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