| Pekka Jaaskelainen | 8690a68 | 2014-02-20 13:52:08 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only |
| 2 | |
| Anastasia Stulova | 7c30533 | 2016-10-28 12:59:39 +0000 | [diff] [blame] | 3 | // Variadic functions |
| 4 | void vararg_f(int, ...); // expected-error {{invalid prototype, variadic arguments are not allowed in OpenCL}} |
| 5 | void __vararg_f(int, ...); |
| 6 | typedef void (*vararg_fptr_t)(int, ...); // expected-error {{invalid prototype, variadic arguments are not allowed in OpenCL}} |
| Alexey Bader | 037dbe95 | 2017-06-02 18:08:58 +0000 | [diff] [blame^] | 7 | // expected-error@-1{{pointers to functions are not allowed}} |
| Anastasia Stulova | 7c30533 | 2016-10-28 12:59:39 +0000 | [diff] [blame] | 8 | int printf(__constant const char *st, ...); // expected-error {{invalid prototype, variadic arguments are not allowed in OpenCL}} |
| 9 | |
| Alexey Bader | 037dbe95 | 2017-06-02 18:08:58 +0000 | [diff] [blame^] | 10 | // Struct type with function pointer field |
| 11 | typedef struct s |
| 12 | { |
| 13 | void (*f)(struct s *self, int *i); // expected-error{{pointers to functions are not allowed}} |
| 14 | } s_t; |
| 15 | |
| Anastasia Stulova | 7c30533 | 2016-10-28 12:59:39 +0000 | [diff] [blame] | 16 | //Function pointer |
| Pekka Jaaskelainen | 8690a68 | 2014-02-20 13:52:08 +0000 | [diff] [blame] | 17 | void foo(void*); |
| 18 | |
| 19 | void bar() |
| 20 | { |
| 21 | // declaring a function pointer is an error |
| 22 | void (*fptr)(int); // expected-error{{pointers to functions are not allowed}} |
| 23 | |
| 24 | // taking the address of a function is an error |
| 25 | foo((void*)foo); // expected-error{{taking address of function is not allowed}} |
| 26 | foo(&foo); // expected-error{{taking address of function is not allowed}} |
| 27 | |
| Anastasia Stulova | cf04d04 | 2016-01-05 14:39:27 +0000 | [diff] [blame] | 28 | // initializing an array with the address of functions is an error |
| 29 | void* vptrarr[2] = {foo, &foo}; // expected-error{{taking address of function is not allowed}} expected-error{{taking address of function is not allowed}} |
| 30 | |
| Pekka Jaaskelainen | 8690a68 | 2014-02-20 13:52:08 +0000 | [diff] [blame] | 31 | // just calling a function is correct |
| 32 | foo(0); |
| 33 | } |