1 /* PR c/85931 - -Wsizeof-pointer-memaccess for strncpy with size of source
3 { dg-require-effective-target alloca }
4 { dg-options "-O2 -Wall -Wstringop-truncation -ftrack-macro-expansion=0" } */
6 typedef __SIZE_TYPE__
size_t;
8 extern char* strncpy (char*, const char*, size_t);
10 extern char a3
[3], b3
[3];
11 extern char a5
[5], b5
[5];
12 extern char ax
[], bx
[];
21 void sink (void*, ...);
23 #define T(d, s, n) sink (strncpy (d, s, n))
25 void test_array (unsigned n
)
28 /* For the following statemenmt, GCC 8.1 issues warning:
30 argument to ‘sizeof’ in ‘strncpy’ call is the same expression
31 as the source; did you mean to use the size of the destination?
33 Since the size of both the source and destination the warning
34 isn't helpful. Verify that it isn't issued. */
35 T (a3
, b3
, sizeof b3
); /* { dg-bogus "\\\[-Wsizeof-pointer-memaccess" } */
37 T (a3
, ax
, sizeof a3
); /* { dg-warning "\\\[-Wstringop-truncation" } */
38 T (ax
, a3
, sizeof a3
); /* { dg-warning "argument to .sizeof. in .strncpy. call is the same expression as the source" } */
43 T (an
, bn
, sizeof bn
); /* { dg-bogus "\\\[-Wsizeof-pointer-memaccess" } */
46 void test_member_array (struct SA
*sa
, unsigned n
)
48 T (sa
->a3
, sa
->b3
, 3);
49 T (sa
->a3
, sa
->b3
, sizeof sa
->b3
); /* { dg-bogus "\\\[-Wsizeof-pointer-memaccess" } */
51 T (sa
->a3
, sa
->ax
, sizeof sa
->a3
); /* { dg-warning "\\\[-Wstringop-truncation" } */
52 T (sa
->ax
, sa
->a3
, sizeof sa
->a3
); /* { dg-warning "argument to .sizeof. in .strncpy. call is the same expression as the source" } */
59 T (x
.an
, x
.bn
, sizeof x
.bn
); /* { dg-bogus "\\\[-Wsizeof-pointer-memaccess" } */