1 /* PR middle-end/84725 - enable attribute nonstring for all narrow character
3 Verify that using attribute nonstring with all three narrow character
4 types is accepted and using arrays and pointers to characters of all
5 three types (including their qualified forms) declared with the
6 attributes doesn't trigger -Wstringop-truncation warnings.
8 { dg-options "-O -Wall -Wstringop-truncation" } */
13 char* strncpy (char*, const char*, __SIZE_TYPE__
);
15 #define NONSTR __attribute__ ((nonstring))
22 signed char NONSTR b
[4];
23 unsigned char NONSTR c
[4];
26 void test_arrays (struct Arrays
*p
, const char *s
)
28 strncpy (p
->a
, s
, sizeof p
->a
);
29 strncpy ((char*)p
->b
, s
, sizeof p
->b
);
30 strncpy ((char*)p
->c
, s
, sizeof p
->c
);
36 signed char NONSTR
*q
;
37 unsigned char NONSTR
*r
;
40 void test_pointers (struct Pointers
*p
)
42 strncpy (p
->p
, S
, sizeof S
- 1);
43 strncpy ((char*)p
->q
, S
, sizeof S
- 1);
44 strncpy ((char*)p
->r
, S
, sizeof S
- 1);
49 const char NONSTR a
[4];
50 const signed char NONSTR b
[4];
51 const unsigned char NONSTR c
[4];
54 void test_const_arrays (struct ConstArrays
*p
, const char *s
)
56 strncpy ((char*)p
->a
, s
, sizeof p
->a
);
57 strncpy ((char*)p
->b
, s
, sizeof p
->b
);
58 strncpy ((char*)p
->c
, s
, sizeof p
->c
);
64 const signed char NONSTR
*q
;
65 const unsigned char NONSTR
*r
;
68 void test_const_pointers (struct ConstPointers
*p
)
70 strncpy ((char*)p
->p
, S
, sizeof S
- 1);
71 strncpy ((char*)p
->q
, S
, sizeof S
- 1);
72 strncpy ((char*)p
->r
, S
, sizeof S
- 1);
77 volatile char NONSTR a
[4];
78 volatile signed char NONSTR b
[4];
79 volatile unsigned char NONSTR c
[4];
82 void test_volatile_arrays (struct VolatileArrays
*p
, const char *s
)
84 strncpy ((char*)p
->a
, s
, sizeof p
->a
);
85 strncpy ((char*)p
->b
, s
, sizeof p
->b
);
86 strncpy ((char*)p
->c
, s
, sizeof p
->c
);
89 struct VolatilePointers
91 volatile char NONSTR
*p
;
92 volatile signed char NONSTR
*q
;
93 volatile unsigned char NONSTR
*r
;
96 void test_volatile_pointers (struct VolatilePointers
*p
)
98 strncpy ((char*)p
->p
, S
, sizeof S
- 1);
99 strncpy ((char*)p
->q
, S
, sizeof S
- 1);
100 strncpy ((char*)p
->r
, S
, sizeof S
- 1);
103 struct ConstVolatileArrays
105 const volatile char NONSTR a
[4];
106 const volatile signed char NONSTR b
[4];
107 const volatile unsigned char NONSTR c
[4];
110 void test_const_volatile_arrays (struct ConstVolatileArrays
*p
, const char *s
)
112 strncpy ((char*)p
->a
, s
, sizeof p
->a
);
113 strncpy ((char*)p
->b
, s
, sizeof p
->b
);
114 strncpy ((char*)p
->c
, s
, sizeof p
->c
);
117 struct ConstVolatilePointers
119 const volatile char NONSTR
*p
;
120 const volatile signed char NONSTR
*q
;
121 const volatile unsigned char NONSTR
*r
;
124 void test_const_volatile_pointers (struct ConstVolatilePointers
*p
)
126 strncpy ((char*)p
->p
, S
, sizeof S
- 1);
127 strncpy ((char*)p
->q
, S
, sizeof S
- 1);
128 strncpy ((char*)p
->r
, S
, sizeof S
- 1);
131 /* { dg-prune-output "-Wdiscarded-qualifiers" } */