@@ -50,6 +50,42 @@ namespace i128 {
50
50
// ref-note {{outside the range}}
51
51
constexpr int128_t Two = (int128_t )1 << 1ul ;
52
52
static_assert (Two == 2 , " " );
53
+
54
+ #if __cplusplus >= 201402L
55
+ template <typename T>
56
+ constexpr T CastFrom (__int128_t A) {
57
+ T B = (T)A;
58
+ return B;
59
+ }
60
+ static_assert (CastFrom<char >(12 ) == 12, "");
61
+ static_assert (CastFrom<unsigned char >(12 ) == 12, "");
62
+ static_assert (CastFrom<long >(12 ) == 12, "");
63
+ static_assert (CastFrom<unsigned short >(12 ) == 12, "");
64
+ static_assert (CastFrom<int128_t >(12 ) == 12, "");
65
+ static_assert (CastFrom<float >(12 ) == 12, "");
66
+ static_assert (CastFrom<double >(12 ) == 12, "");
67
+ static_assert (CastFrom<long double >(12 ) == 12, "");
68
+
69
+ template <typename T>
70
+ constexpr __int128 CastTo (T A) {
71
+ int128_t B = (int128_t )A;
72
+ return B;
73
+ }
74
+ static_assert (CastTo<char >(12 ) == 12, "");
75
+ static_assert (CastTo<unsigned char >(12 ) == 12, "");
76
+ static_assert (CastTo<long >(12 ) == 12, "");
77
+ static_assert (CastTo<unsigned long long >(12 ) == 12, "");
78
+ static_assert (CastTo<float >(12 ) == 12, "");
79
+ static_assert (CastTo<double >(12 ) == 12, "");
80
+ static_assert (CastTo<long double >(12 ) == 12, "");
81
+ #endif
82
+
83
+ constexpr int128_t Error = __LDBL_MAX__; // ref-warning {{implicit conversion of out of range value}} \
84
+ // ref-error {{must be initialized by a constant expression}} \
85
+ // ref-note {{is outside the range of representable values of type}} \
86
+ // expected-warning {{implicit conversion of out of range value}} \
87
+ // expected-error {{must be initialized by a constant expression}} \
88
+ // expected-note {{is outside the range of representable values of type}}
53
89
}
54
90
55
91
constexpr bool b = number;
0 commit comments