Skip to content

Commit 138e116

Browse files
Standard Library Modules: Add compiler workarounds for <random> (#4906)
1 parent 5f11927 commit 138e116

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

stl/inc/__msvc_int128.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,9 @@ struct _Unsigned128 : _Base128 {
707707
using _Signed_type = _Signed128;
708708
using _Unsigned_type = _Unsigned128;
709709

710-
#if !_HAS_CXX17
710+
#if !_HAS_CXX17 || (_HAS_CXX20 && !defined(__clang__) && !defined(__EDG__)) // TRANSITION, DevCom-10729775
711711
constexpr _Unsigned128() noexcept : _Base128{} {}
712-
#endif // !_HAS_CXX17
712+
#endif // ^^^ workaround for C++20 MSVC modules and header units; should be guarded for !_HAS_CXX17 only ^^^
713713

714714
using _Base128::_Base128;
715715
constexpr explicit _Unsigned128(const _Base128& _That) noexcept : _Base128{_That} {}
@@ -1024,9 +1024,9 @@ struct _Signed128 : _Base128 {
10241024
using _Signed_type = _Signed128;
10251025
using _Unsigned_type = _Unsigned128;
10261026

1027-
#if !_HAS_CXX17
1027+
#if !_HAS_CXX17 || (_HAS_CXX20 && !defined(__clang__) && !defined(__EDG__)) // TRANSITION, DevCom-10729775
10281028
constexpr _Signed128() noexcept : _Base128{} {}
1029-
#endif // !_HAS_CXX17
1029+
#endif // ^^^ workaround for C++20 MSVC modules and header units; should be guarded for !_HAS_CXX17 only ^^^
10301030

10311031
using _Base128::_Base128;
10321032
constexpr explicit _Signed128(const _Base128& _That) noexcept : _Base128{_That} {}

tests/std/include/test_header_units_and_modules.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,14 @@ void test_random() {
593593
minstd_rand0 lcg;
594594
lcg.discard(9999);
595595
assert(lcg() == 1043618065); // N4868 [rand.predef]/1
596+
597+
#ifndef _MSVC_INTERNAL_TESTING // TRANSITION, VSO-2226569
598+
// Test coverage for GH-4899 "Standard Library Modules: uniform_real_distribution emits
599+
// error C2512: 'std::_Unsigned128': no appropriate default constructor available":
600+
const double val = generate_canonical<double, 53>(lcg);
601+
assert(val >= 0.0);
602+
assert(val < 1.0);
603+
#endif // ^^^ no workaround ^^^
596604
}
597605

598606
void test_ranges() {

0 commit comments

Comments
 (0)