PR middle-end/85602 - -Wsizeof-pointer-memaccess for strncat with size of source
[official-gcc.git] / gcc / testsuite / gcc.dg / Wattributes-8.c
bloba4b4c00c08f4470c6bccb4f319a85860971bf409
1 /* PR middle-end/84108 - incorrect -Wattributes warning for packed/aligned
2 conflict on struct members
3 { dg-do compile }
4 { dg-options "-Wall -Wattributes" } */
6 #define ATTR(list) __attribute__ (list)
7 #define ASSERT(e) _Static_assert (e, #e)
9 /* GCC is inconsistent in how it treats attribute aligned between
10 variable and member declarations. Attribute aligned alone is
11 sufficient to reduce a variable's alignment requirement but
12 the attribute must be paired with packed to have the same
13 effect on a member. Worse, declaring a variable both aligned
14 and packed emits a warning. */
16 /* Avoid exercising this since emitting a warning for these given
17 the requirement for members seems like a misfeature:
18 int a ATTR ((packed, aligned (2))); // -Wattributes
19 int b ATTR ((aligned (2), packed)); // -Wattributes
20 ASSERT (_Alignof (a) == 2);
21 ASSERT (_Alignof (b) == 2); */
23 int c ATTR ((aligned (2))); // okay (reduces alignment)
24 ASSERT (_Alignof (c) == 2);
26 struct {
27 int a ATTR ((packed, aligned (2))); /* { dg-bogus "\\\[-Wattributes" } */
28 int b ATTR ((aligned (2), packed)); /* { dg-bogus "\\\[-Wattributes" } */
30 /* Avoid exercising this since the attribute has no effect yet
31 there is no warning.
32 int c ATTR ((aligned (2))); // missing warning? */
33 } s;
35 ASSERT (_Alignof (s.a) == 2);
36 ASSERT (_Alignof (s.b) == 2);
38 /* ASSERT (_Alignof (s.c) == 4); */