Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify %s |
| 2 | void f() { |
| 3 | int *ptr = malloc(sizeof(int) * 10); // expected-warning{{implicitly declaring C library function 'malloc' with type}} \ |
| 4 | // expected-note{{please include the header <stdlib.h> or explicitly provide a declaration for 'malloc'}} \ |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 5 | // expected-note{{'malloc' is a builtin with type 'void *}} |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 6 | } |
| 7 | |
| 8 | void *alloca(__SIZE_TYPE__); // redeclaration okay |
| 9 | |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 10 | int *calloc(__SIZE_TYPE__, __SIZE_TYPE__); // expected-warning{{incompatible redeclaration of library function 'calloc' will be ignored}} \ |
| 11 | // expected-note{{'calloc' is a builtin with type 'void *}} |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 12 | |
| 13 | |
| 14 | void g(int malloc) { // okay: these aren't functions |
| 15 | int calloc = 1; |
| 16 | } |
| 17 | |
| 18 | void h() { |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 19 | int malloc(int); // expected-warning{{incompatible redeclaration of library function 'malloc' will be ignored}} |
| 20 | int strcpy(int); // expected-warning{{incompatible redeclaration of library function 'strcpy' will be ignored}} \ |
| 21 | // expected-note{{'strcpy' is a builtin with type 'char *(char *, char const *)'}} |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 22 | } |
Douglas Gregor | 370ab3f | 2009-02-14 01:52:53 +0000 | [diff] [blame] | 23 | |
| 24 | void f2() { |
| 25 | fprintf(0, "foo"); // expected-error{{implicit declaration of 'fprintf' requires inclusion of the header <stdio.h>}} |
| 26 | } |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 27 | |
| 28 | // PR2892 |
| 29 | void __builtin_object_size(); // expected-error{{conflicting types}} \ |
| 30 | // expected-note{{'__builtin_object_size' is a builtin with type}} |
| 31 | |
| 32 | int a[10]; |
| 33 | |
| 34 | int f0() { |
| 35 | return __builtin_object_size(&a); // expected-error {{too few arguments to function}} |
| 36 | } |
| 37 | |
| 38 | void * realloc(void *p, int size) { // expected-warning{{incompatible redeclaration of library function 'realloc' will be ignored}} \ |
Eli Friedman | edbb94c | 2009-02-18 00:52:29 +0000 | [diff] [blame] | 39 | // expected-note{{'realloc' is a builtin with type 'void *(void *,}} |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 40 | return p; |
| 41 | } |