]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-3.c
1 /* PR c/83656 - missing -Wbuiltin-declaration-mismatch on declaration
4 { dg-options "-Wbuiltin-declaration-mismatch" } */
6 typedef __SIZE_TYPE__
size_t;
8 /* Built-ins declared without a prototype are not diagnosed by default
9 (without -Wextra) except when their return type doesn't match. */
10 int abort (); /* { dg-warning "\\\[-Wbuiltin-declaration-mismatch]" } */
12 /* Built-ins declared without a prototype are not diagnosed without -Wextra. */
18 void test_call_abort (void)
20 /* Verify that a valid call to abort() is not diagnosed. */
23 /* Unfortunately, the incompatible declaration above makes GCC "forget"
24 that abort() is a built-in and so the invalid calls below aren't
25 diagnosed. The only saving grace is that the invalid declaration
26 that differs in the return type is diagnosed by default. */
27 abort (1); /* { dg-warning "too many arguments to built-in function .abort. expecting 0" "pr?????" { xfail *-*-* } } */
29 abort (1, 2); /* { dg-warning "too many arguments" "pr?????" { xfail *-*-* } } */
33 void test_call_exit (void)
35 /* Verify that valid calls to exit are not diagnosed. */
39 /* Also verify calls to the built-in. */
40 __builtin_exit ('\0');
44 exit (); /* { dg-warning "too few arguments to built-in function 'exit' expecting 1" } */
46 exit (1, 2); /* { dg-warning "too many arguments" } */
48 /* Verify that passing incompatible arguments triggers a warning. */
49 exit (""); /* { dg-warning "\\\[-Wint-conversion]" } */
51 struct S
{ int i
; } s
= { 0 };
52 exit (s
); /* { dg-warning "incompatible type for argument 1" } */
56 void test_call_memcpy (void *p
, const void *q
, size_t n
)
60 memcpy (); /* { dg-warning "too few arguments to built-in function 'memcpy' expecting 3" } */
62 memcpy (p
); /* { dg-warning "too few arguments to built-in function 'memcpy' expecting 3" } */
64 memcpy (p
, q
); /* { dg-warning "too few arguments to built-in function 'memcpy' expecting 3" } */
66 memcpy (q
, p
, n
); /* { dg-warning "\\\[-Wdiscarded-qualifiers]" } */
68 memcpy (p
, n
, q
); /* { dg-warning "\\\[-Wint-conversion]" } */
70 memcpy (p
, q
, n
, 0); /* { dg-warning "too many arguments to built-in function 'memcpy' expecting 3" } */
74 typedef void* (memcpy_t
)(void*, const void*, size_t);
75 typedef void* (memset_t
)(void*, int, size_t);
79 /* Verify that initialization of a pointer by the address of a built-in
80 function of a matching type declared without a prototype doesn't
81 trigger a warning... */
82 memset_t
*pmemset
= memset
;
84 /* ...but initialization by the address of an incompatible built-in
85 does even without -Wextra. */
86 memcpy_t
*pmemcpy
= memset
; /* { dg-warning "\\\[-Wincompatible-pointer-types]" } */
90 void test_assign (void)
92 /* Same as above but for assignment. */
97 pmemcpy
= memset
; /* { dg-warning "\\\[-Wincompatible-pointer-types]" } */
101 /* Verify that passing built-ins declared without a prototype to
102 functions that expect a pointer to a function of a specific type
103 is diagnosed. Ditto for return statements. */
105 void take_memcpy (memcpy_t
*);
106 void take_any (int, ...);
108 memset_t
* pass_args (int i
)
110 take_memcpy (memcpy
);
111 take_memcpy (memset
); /* { dg-warning "\\\[-Wincompatible-pointer-types]" } */
113 take_any (0, i
? memcpy
: memset
); /* { dg-warning "\\\[-Wincompatible-pointer-types]" } */
115 return memcpy
; /* { dg-warning "\\\[-Wincompatible-pointer-types]" } */