diff options
Diffstat (limited to 'test/Sema/overloadable.c')
-rw-r--r-- | test/Sema/overloadable.c | 100 |
1 files changed, 91 insertions, 9 deletions
diff --git a/test/Sema/overloadable.c b/test/Sema/overloadable.c index be9b862f2934f..4bdec85f9ca99 100644 --- a/test/Sema/overloadable.c +++ b/test/Sema/overloadable.c @@ -3,12 +3,15 @@ int var __attribute__((overloadable)); // expected-error{{'overloadable' attribute only applies to functions}} void params(void) __attribute__((overloadable(12))); // expected-error {{'overloadable' attribute takes no arguments}} -int *f(int) __attribute__((overloadable)); // expected-note 2{{previous overload of function is here}} -float *f(float); // expected-error{{overloaded function 'f' must have the 'overloadable' attribute}} +int *f(int) __attribute__((overloadable)); // expected-note{{previous overload of function is here}} +float *f(float); int *f(int); // expected-error{{redeclaration of 'f' must have the 'overloadable' attribute}} \ // expected-note{{previous declaration is here}} double *f(double) __attribute__((overloadable)); // okay, new +// Ensure we don't complain about overloadable on implicitly declared functions. +int isdigit(int) __attribute__((overloadable)); + void test_f(int iv, float fv, double dv) { int *ip = f(iv); float *fp = f(fv); @@ -71,19 +74,19 @@ void test() { f1(); } -void before_local_1(int) __attribute__((overloadable)); // expected-note {{here}} +void before_local_1(int) __attribute__((overloadable)); void before_local_2(int); // expected-note {{here}} void before_local_3(int) __attribute__((overloadable)); void local() { - void before_local_1(char); // expected-error {{must have the 'overloadable' attribute}} - void before_local_2(char) __attribute__((overloadable)); // expected-error {{conflicting types}} + void before_local_1(char); + void before_local_2(char); // expected-error {{conflicting types}} void before_local_3(char) __attribute__((overloadable)); - void after_local_1(char); // expected-note {{here}} - void after_local_2(char) __attribute__((overloadable)); // expected-note {{here}} + void after_local_1(char); + void after_local_2(char) __attribute__((overloadable)); void after_local_3(char) __attribute__((overloadable)); } -void after_local_1(int) __attribute__((overloadable)); // expected-error {{conflicting types}} -void after_local_2(int); // expected-error {{must have the 'overloadable' attribute}} +void after_local_1(int) __attribute__((overloadable)); +void after_local_2(int); void after_local_3(int) __attribute__((overloadable)); // Make sure we allow C-specific conversions in C. @@ -152,6 +155,85 @@ void dropping_qualifiers_is_incompatible() { foo(vcharbuf); // expected-error{{call to 'foo' is ambiguous}} expected-note@-4{{candidate function}} expected-note@-3{{candidate function}} } +void overloadable_with_global() { + void wg_foo(void) __attribute__((overloadable)); // expected-note{{previous}} + void wg_foo(int) __attribute__((overloadable)); +} + +int wg_foo; // expected-error{{redefinition of 'wg_foo' as different kind of symbol}} + +#if !__has_extension(overloadable_unmarked) +#error "We should have unmarked overload support" +#endif + +void to_foo0(int); +void to_foo0(double) __attribute__((overloadable)); // expected-note{{previous overload}} +void to_foo0(int); +void to_foo0(double); // expected-error{{must have the 'overloadable' attribute}} +void to_foo0(int); + +void to_foo1(int) __attribute__((overloadable)); // expected-note 2{{previous overload}} +void to_foo1(double); +void to_foo1(int); // expected-error{{must have the 'overloadable' attribute}} +void to_foo1(double); +void to_foo1(int); // expected-error{{must have the 'overloadable' attribute}} + +void to_foo2(int); // expected-note{{previous unmarked overload}} +void to_foo2(double) __attribute__((overloadable)); // expected-note 2{{previous overload}} +void to_foo2(int) __attribute__((overloadable)); // expected-error {{must not have the 'overloadable' attribute}} +void to_foo2(double); // expected-error{{must have the 'overloadable' attribute}} +void to_foo2(int); +void to_foo2(double); // expected-error{{must have the 'overloadable' attribute}} +void to_foo2(int); + +void to_foo3(int); +void to_foo3(double) __attribute__((overloadable)); // expected-note{{previous overload}} +void to_foo3(int); +void to_foo3(double); // expected-error{{must have the 'overloadable' attribute}} + +void to_foo4(int) __attribute__((overloadable)); // expected-note{{previous overload}} +void to_foo4(int); // expected-error{{must have the 'overloadable' attribute}} +void to_foo4(double) __attribute__((overloadable)); + +void to_foo5(int); +void to_foo5(int); // expected-note 3{{previous unmarked overload}} +void to_foo5(float) __attribute__((overloadable)); +void to_foo5(double); // expected-error{{at most one overload for a given name may lack the 'overloadable' attribute}} +void to_foo5(float) __attribute__((overloadable)); +void to_foo5(short); // expected-error{{at most one overload for a given name may lack the 'overloadable' attribute}} +void to_foo5(long); // expected-error{{at most one overload for a given name may lack the 'overloadable' attribute}} +void to_foo5(double) __attribute__((overloadable)); + +void to_foo6(int) __attribute__((enable_if(1, ""), overloadable)); // expected-note{{previous overload}} +void to_foo6(int) __attribute__((enable_if(1, ""))); // expected-error{{must have the 'overloadable' attribute}} +void to_foo6(int) __attribute__((enable_if(1, ""), overloadable)); + +void to_foo7(int) __attribute__((enable_if(1, ""))); // expected-note{{previous unmarked overload}} +void to_foo7(int) __attribute__((enable_if(1, ""), overloadable)); // expected-error{{must not have the 'overloadable' attribute}} +void to_foo7(int) __attribute__((enable_if(1, ""))); + +void to_foo8(char *__attribute__((pass_object_size(0)))) + __attribute__((enable_if(1, ""))); +void to_foo8(char *__attribute__((pass_object_size(0)))) + __attribute__((overloadable)); + +void to_foo9(int); // expected-note{{previous unmarked overload}} +// FIXME: It would be nice if we did better with the "previous unmarked +// overload" diag. +void to_foo9(int) __attribute__((overloadable)); // expected-error{{must not have the 'overloadable' attribute}} expected-note{{previous declaration}} expected-note{{previous unmarked overload}} +void to_foo9(float); // expected-error{{conflicting types for 'to_foo9'}} +void to_foo9(float) __attribute__((overloadable)); +void to_foo9(double); // expected-error{{at most one overload for a given name may lack the 'overloadable' attribute}} +void to_foo9(double) __attribute__((overloadable)); + +void to_foo10(int) __attribute__((overloadable)); +void to_foo10(double); // expected-note{{previous unmarked overload}} +// no "note: previous redecl" if no previous decl has `overloadable` +// spelled out +void to_foo10(float); // expected-error{{at most one overload for a given name may lack the 'overloadable' attribute}} +void to_foo10(float); // expected-error{{must have the 'overloadable' attribute}} +void to_foo10(float); // expected-error{{must have the 'overloadable' attribute}} + // Bug: we used to treat `__typeof__(foo)` as though it was `__typeof__(&foo)` // if `foo` was overloaded with only one function that could have its address // taken. |