]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gcc.dg/builtin-has-attribute.c
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / builtin-has-attribute.c
CommitLineData
98f08eb8
MS
1/* Verify that defining a type in __builtin_has_attribute triggers
2 the expected -Wc++-compat warning and evaluates as expected.
3 Also verify that the expression in __builtin_has_attribute is
4 not evaluated.
5
673670da
MS
6 { dg-do compile }
7 { dg-options "-O2 -Wall -Wc++-compat -fdump-tree-optimized -ftrack-macro-expansion=0" } */
98f08eb8
MS
8
9#define ATTR(list) __attribute__ (list)
10
11#define A(expect, sym, attr) \
12 typedef int Assert [1 - 2 * !(__builtin_has_attribute (sym, attr) == expect)]
13
98f08eb8
MS
14#define assert(expr) \
15 ((expr) \
16 ? (void)0 \
17 : (__builtin_printf ("Assertion failed on line %i: %s\n", \
18 __LINE__, #expr), \
19 ++nfails))
20
21A (0, struct A { int i; }, aligned); /* { dg-warning "expression is invalid in C\\\+\\\+" } */
22A (1, struct ATTR ((aligned)) B { int i; }, aligned); /* { dg-warning "expression is invalid in C\\\+\\\+" } */
23
24
673670da 25static int f (void)
98f08eb8
MS
26{
27 __builtin_abort ();
28}
29
98f08eb8
MS
30int main (void)
31{
673670da
MS
32 int n = 0, nfails = 0;
33
98f08eb8
MS
34 assert (0 == __builtin_has_attribute (int[n++], aligned));
35 assert (1 == __builtin_has_attribute (ATTR ((aligned)) int[n++], aligned));
36 assert (1 == __builtin_has_attribute (ATTR ((aligned)) int[f ()], aligned));
37 assert (1 == 1);
38
673670da
MS
39 if (n)
40 __builtin_abort ();
41
98f08eb8
MS
42 if (nfails)
43 __builtin_abort ();
44
45 return 0;
46}
673670da
MS
47
48/* { dg-final { scan-tree-dump-times "abort" 0 "optimized" } } */