1 /* Test C23 constexpr. Invalid code, compilation tests, DFP. */
2 /* { dg-do compile } */
3 /* { dg-options "-std=c23 -pedantic-errors" } */
5 /* Test conversions between binary and decimal. */
6 constexpr double v2
= 0.0DF
; /* { dg-error "'constexpr' initializer for a binary floating-point type is of decimal type" } */
7 constexpr double v2i
= __builtin_infd32 (); /* { dg-error "'constexpr' initializer for a binary floating-point type is of decimal type" } */
8 constexpr double v2n
= __builtin_nand32 (""); /* { dg-error "'constexpr' initializer for a binary floating-point type is of decimal type" } */
9 constexpr _Decimal128 v2d
= 0x1p
-100f
; /* { dg-error "'constexpr' initializer not representable in type of object" } */
11 /* A conversion from signaling NaN to quiet NaN in a different format is not
12 valid for constexpr. */
13 constexpr _Decimal32 v3
= __builtin_nansd64 (""); /* { dg-error "'constexpr' initializer not representable in type of object" } */
14 constexpr _Decimal32 v4
= __builtin_nansd128 (""); /* { dg-error "'constexpr' initializer not representable in type of object" } */
15 constexpr _Decimal64 v5
= __builtin_nansd32 (""); /* { dg-error "'constexpr' initializer not representable in type of object" } */
16 constexpr _Decimal64 v6
= __builtin_nansd128 (""); /* { dg-error "'constexpr' initializer not representable in type of object" } */
17 constexpr _Decimal128 v7
= __builtin_nansd32 (""); /* { dg-error "'constexpr' initializer not representable in type of object" } */
18 constexpr _Decimal128 v8
= __builtin_nansd64 (""); /* { dg-error "'constexpr' initializer not representable in type of object" } */
20 /* Test out-of-range values, including integers. */
21 constexpr _Decimal32 v9
= 12345678; /* { dg-error "'constexpr' initializer not representable in type of object" } */
22 constexpr _Decimal64 v10
= (unsigned long long) -1; /* { dg-error "'constexpr' initializer not representable in type of object" } */
23 constexpr _Decimal32 v11
= __DEC64_MIN__
; /* { dg-error "'constexpr' initializer not representable in type of object" } */
24 constexpr _Decimal64 v12
= -__DEC128_MAX__
; /* { dg-error "'constexpr' initializer not representable in type of object" } */
25 constexpr _Decimal64 v13
= 12345678901234567890.DL
; /* { dg-error "'constexpr' initializer not representable in type of object" } */
27 /* Test cases where the value can be represented, but the quantum exponent
29 constexpr _Decimal32 v14
= 0e-200DD
; /* { dg-error "'constexpr' initializer not representable in type of object" } */
30 constexpr _Decimal32 v15
= 0e200DL
; /* { dg-error "'constexpr' initializer not representable in type of object" } */
35 (constexpr double) { 0.0DF
}; /* { dg-error "'constexpr' initializer for a binary floating-point type is of decimal type" } */
36 (constexpr double) { __builtin_infd32 () }; /* { dg-error "'constexpr' initializer for a binary floating-point type is of decimal type" } */
37 (constexpr double) { __builtin_nand32 ("") }; /* { dg-error "'constexpr' initializer for a binary floating-point type is of decimal type" } */
38 (constexpr _Decimal128
) { 0x1p
-100f
}; /* { dg-error "'constexpr' initializer not representable in type of object" } */
39 (constexpr _Decimal32
) { __builtin_nansd64 ("") }; /* { dg-error "'constexpr' initializer not representable in type of object" } */
40 (constexpr _Decimal32
) { __builtin_nansd128 ("") }; /* { dg-error "'constexpr' initializer not representable in type of object" } */
41 (constexpr _Decimal64
) { __builtin_nansd32 ("") }; /* { dg-error "'constexpr' initializer not representable in type of object" } */
42 (constexpr _Decimal64
) { __builtin_nansd128 ("") }; /* { dg-error "'constexpr' initializer not representable in type of object" } */
43 (constexpr _Decimal128
) { __builtin_nansd32 ("") }; /* { dg-error "'constexpr' initializer not representable in type of object" } */
44 (constexpr _Decimal128
) { __builtin_nansd64 ("") }; /* { dg-error "'constexpr' initializer not representable in type of object" } */
45 (constexpr _Decimal32
) { 12345678 }; /* { dg-error "'constexpr' initializer not representable in type of object" } */
46 (constexpr _Decimal64
) { (unsigned long long) -1 }; /* { dg-error "'constexpr' initializer not representable in type of object" } */
47 (constexpr _Decimal32
) { __DEC64_MIN__
}; /* { dg-error "'constexpr' initializer not representable in type of object" } */
48 (constexpr _Decimal64
) { -__DEC128_MAX__
}; /* { dg-error "'constexpr' initializer not representable in type of object" } */
49 (constexpr _Decimal64
) { 12345678901234567890.DL
}; /* { dg-error "'constexpr' initializer not representable in type of object" } */
50 (constexpr _Decimal32
) { 0e-200DD
}; /* { dg-error "'constexpr' initializer not representable in type of object" } */
51 (constexpr _Decimal32
) { 0e200DL
}; /* { dg-error "'constexpr' initializer not representable in type of object" } */