annotate gcc/testsuite/c-c++-common/builtin_location.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* PR c++/66561 - __builtin_LINE at al. should yield constant expressions */
kono
parents:
diff changeset
2 /* { dg-do compile } */
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 #if __cplusplus >= 201103L
kono
parents:
diff changeset
5 # define Assert(expr) static_assert ((expr), #expr)
kono
parents:
diff changeset
6 #elif __STDC_VERSION__ >= 201112L
kono
parents:
diff changeset
7 # define Assert(expr) _Static_assert ((expr), #expr)
kono
parents:
diff changeset
8 #else
kono
parents:
diff changeset
9 # define CONCAT(a, b) a ## b
kono
parents:
diff changeset
10 # define CAT(a, b) CONCAT (a, b)
kono
parents:
diff changeset
11 # define Assert(expr) typedef int CAT (Assert_, __LINE__) [1 - 2 * !(expr)]
kono
parents:
diff changeset
12 #endif
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 /* Verify (in C) that __builtin_FILE() yields an address constant.
kono
parents:
diff changeset
15 This test is ineffective in C++ where initializers of global
kono
parents:
diff changeset
16 objects need not be constant expressions. */
kono
parents:
diff changeset
17 const char* const file = __builtin_FILE ();
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 /* Verify (in C) that __builtin_FUNCTION() yields an address constant. */
kono
parents:
diff changeset
20 const char* const function = __builtin_FUNCTION ();
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22 /* Also verify that __builtin_constant_p() returns true for both. */
kono
parents:
diff changeset
23 Assert (__builtin_constant_p (__builtin_FILE ()));
kono
parents:
diff changeset
24 Assert (__builtin_constant_p (__builtin_FUNCTION ()));
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 /* Verify (in both C and C++ 11 and later) that both __builtin_FILE ()
kono
parents:
diff changeset
27 and __builtin_FUNCTION() yield an address constant by making use
kono
parents:
diff changeset
28 of a GCC extension that allows operands of arithmetic constant
kono
parents:
diff changeset
29 expressions to be address constants. (Subtracting two literals
kono
parents:
diff changeset
30 from one another is undefined in both C and C++ and should be
kono
parents:
diff changeset
31 diagnosed. See c/70772.) */
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 #pragma GCC diagnostic push
kono
parents:
diff changeset
34 #pragma GCC diagnostic ignored "-Waddress"
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 enum E0 {
kono
parents:
diff changeset
37 e0 = __FILE__ - __FILE__,
kono
parents:
diff changeset
38 e1 = __builtin_FILE () - __builtin_FILE (),
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 #if !__cplusplus || __cplusplus >= 201103L
kono
parents:
diff changeset
41 /* Skip this test in C++ 98 where GCC rejects __FUNCTION__ in constant
kono
parents:
diff changeset
42 expressions. */
kono
parents:
diff changeset
43 e2 = __FUNCTION__ - __FUNCTION__,
kono
parents:
diff changeset
44 e3 = __builtin_FUNCTION () - __builtin_FUNCTION ()
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 #endif
kono
parents:
diff changeset
47 };
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 #pragma GCC diagnostic pop
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 /* Verify that __builtin_LINE () yields an integer constant expression. */
kono
parents:
diff changeset
52 #line 13
kono
parents:
diff changeset
53 int a [__builtin_LINE ()][__builtin_LINE ()];
kono
parents:
diff changeset
54 enum F { f0 = __builtin_LINE () };
kono
parents:
diff changeset
55 struct S { unsigned bitfield: __builtin_LINE (); } s;
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 Assert (__builtin_constant_p (__builtin_LINE ()));