@@ -103,7 +103,7 @@ namespace simple {
103
103
static_assert (check_round_trip<unsigned >((int )0x12345678 ));
104
104
static_assert (check_round_trip<unsigned >((int )0x87654321 ));
105
105
static_assert (check_round_trip<unsigned >((int )0x0C05FEFE ));
106
- // static_assert(round_trip<float>((int)0x0C05FEFE));
106
+ static_assert (round_trip<float >((int )0x0C05FEFE ));
107
107
108
108
109
109
// / This works in GCC and in the bytecode interpreter, but the current interpreter
@@ -449,3 +449,57 @@ struct ref_mem {
449
449
// both-error@+2 {{constexpr variable 'run_ref_mem' must be initialized by a constant expression}}
450
450
// both-note@+1 {{bit_cast from a type with a reference member is not allowed in a constant expression}}
451
451
constexpr intptr_t run_ref_mem = __builtin_bit_cast(intptr_t , ref_mem{global_int});
452
+
453
+ namespace test_long_double {
454
+ #ifdef __x86_64
455
+ #if 0
456
+ constexpr __int128_t test_cast_to_int128 = bit_cast<__int128_t>((long double)0); // expected-error{{must be initialized by a constant expression}}\
457
+ // expected-note{{in call}}
458
+ #endif
459
+ constexpr long double ld = 3.1425926539 ;
460
+
461
+ struct bytes {
462
+ unsigned char d[16 ];
463
+ };
464
+
465
+ // static_assert(round_trip<bytes>(ld), "");
466
+
467
+ static_assert (round_trip<long double >(10 .0L ));
468
+
469
+ #if 0
470
+ constexpr bool f(bool read_uninit) {
471
+ bytes b = bit_cast<bytes>(ld);
472
+ unsigned char ld_bytes[10] = {
473
+ 0x0, 0x48, 0x9f, 0x49, 0xf0,
474
+ 0x3c, 0x20, 0xc9, 0x0, 0x40,
475
+ };
476
+
477
+ for (int i = 0; i != 10; ++i)
478
+ if (ld_bytes[i] != b.d[i])
479
+ return false;
480
+
481
+ if (read_uninit && b.d[10]) // expected-note{{read of uninitialized object is not allowed in a constant expression}}
482
+ return false;
483
+
484
+ return true;
485
+ }
486
+
487
+ static_assert(f(/*read_uninit=*/false), "");
488
+ static_assert(f(/*read_uninit=*/true), ""); // expected-error{{static assertion expression is not an integral constant expression}} \
489
+ // expected-note{{in call to 'f(true)'}}
490
+ #endif
491
+ constexpr bytes ld539 = {
492
+ 0x0 , 0x0 , 0x0 , 0x0 ,
493
+ 0x0 , 0x0 , 0xc0 , 0x86 ,
494
+ 0x8 , 0x40 , 0x0 , 0x0 ,
495
+ 0x0 , 0x0 , 0x0 , 0x0 ,
496
+ };
497
+
498
+ constexpr long double fivehundredandthirtynine = 539.0 ;
499
+
500
+ static_assert (bit_cast<long double >(ld539) == fivehundredandthirtynine, "");
501
+
502
+ #else
503
+ static_assert (round_trip<__int128_t >(34 .0L ));
504
+ #endif
505
+ }
0 commit comments