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