aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-02-12 19:25:19 +0000
committerDouglas Gregor <dgregor@apple.com>2009-02-12 19:25:19 +0000
commit4fc526d80d829b2f8c294a4c3360c820f1f6e7c2 (patch)
treefa85549d5008524203381194b4f7cb41a60cb318
parent1fd03615dc8303ac3f03525758ef172cf88b2051 (diff)
Add missing test for the "overloadable" attribute
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64396 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--test/Sema/overloadable.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/Sema/overloadable.c b/test/Sema/overloadable.c
new file mode 100644
index 0000000000..5118e40ab0
--- /dev/null
+++ b/test/Sema/overloadable.c
@@ -0,0 +1,37 @@
+// RUN: clang -fsyntax-only -verify %s
+
+int var __attribute__((overloadable)); // expected-error{{'overloadable' attribute can only be applied to a function}}
+
+int *f(int) __attribute__((overloadable)); // expected-note{{previous overload of function is here}}
+float *f(float); // expected-error{{overloaded function 'f' must have the 'overloadable' attribute}}
+int *f(int); // expected-note{{previous declaration is here}}
+double *f(double) __attribute__((overloadable)); // okay, new
+
+void test_f(int iv, float fv, double dv) {
+ int *ip = f(iv);
+ float *fp = f(fv);
+ double *dp = f(dv);
+}
+
+int *accept_funcptr(int (*)()) __attribute__((overloadable)); // \
+ // expected-note{{candidate function}}
+float *accept_funcptr(int (*)(int, double)) __attribute__((overloadable)); // \
+ // expected-note{{candidate function}}
+
+void test_funcptr(int (*f1)(int, double),
+ int (*f2)(int, float)) {
+ float *fp = accept_funcptr(f1);
+ accept_funcptr(f2); // expected-error{{no matching function for call to 'accept_funcptr'; candidates are:}}
+}
+
+struct X { int x; float y; };
+struct Y { int x; float y; };
+int* accept_struct(struct X x) __attribute__((overloadable));
+float* accept_struct(struct Y y) __attribute__((overloadable));
+
+void test_struct(struct X x, struct Y y) {
+ int *ip = accept_struct(x);
+ float *fp = accept_struct(y);
+}
+
+double *f(int) __attribute__((overloadable)); // expected-error{{conflicting types for 'f'}}