1 /* PR c/85931 - -Wsizeof-pointer-memaccess for strncpy with size of source
3 { dg-options "-O2 -Wall -Wstringop-truncation -ftrack-macro-expansion=0" } */
5 typedef __SIZE_TYPE__
size_t;
7 extern char* strncpy (char*, const char*, size_t);
9 extern char a3
[3], b3
[3];
10 extern char a5
[5], b5
[5];
11 extern char ax
[], bx
[];
20 void sink (void*, ...);
22 #define T(d, s, n) sink (strncpy (d, s, n))
24 void test_array (unsigned n
)
27 /* For the following statemenmt, GCC 8.1 issues warning:
29 argument to ‘sizeof’ in ‘strncpy’ call is the same expression
30 as the source; did you mean to use the size of the destination?
32 Since the size of both the source and destination the warning
33 isn't helpful. Verify that it isn't issued. */
34 T (a3
, b3
, sizeof b3
); /* { dg-bogus "\\\[-Wsizeof-pointer-memaccess" } */
36 T (a3
, ax
, sizeof a3
); /* { dg-warning "\\\[-Wstringop-truncation" } */
37 T (ax
, a3
, sizeof a3
); /* { dg-warning "argument to .sizeof. in .strncpy. call is the same expression as the source" } */
42 T (an
, bn
, sizeof bn
); /* { dg-bogus "\\\[-Wsizeof-pointer-memaccess" } */
45 void test_member_array (struct SA
*sa
, unsigned n
)
47 T (sa
->a3
, sa
->b3
, 3);
48 T (sa
->a3
, sa
->b3
, sizeof sa
->b3
); /* { dg-bogus "\\\[-Wsizeof-pointer-memaccess" } */
50 T (sa
->a3
, sa
->ax
, sizeof sa
->a3
); /* { dg-warning "\\\[-Wstringop-truncation" } */
51 T (sa
->ax
, sa
->a3
, sizeof sa
->a3
); /* { dg-warning "argument to .sizeof. in .strncpy. call is the same expression as the source" } */
58 T (x
.an
, x
.bn
, sizeof x
.bn
); /* { dg-bogus "\\\[-Wsizeof-pointer-memaccess" } */