Skip to content

Commit

Permalink
Standard Library Modules: Add compiler workarounds for <random> (#4906
Browse files Browse the repository at this point in the history
)
  • Loading branch information
StephanTLavavej authored Aug 25, 2024
1 parent 5f11927 commit 138e116
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions stl/inc/__msvc_int128.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,9 @@ struct _Unsigned128 : _Base128 {
using _Signed_type = _Signed128;
using _Unsigned_type = _Unsigned128;

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

using _Base128::_Base128;
constexpr explicit _Unsigned128(const _Base128& _That) noexcept : _Base128{_That} {}
Expand Down Expand Up @@ -1024,9 +1024,9 @@ struct _Signed128 : _Base128 {
using _Signed_type = _Signed128;
using _Unsigned_type = _Unsigned128;

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

using _Base128::_Base128;
constexpr explicit _Signed128(const _Base128& _That) noexcept : _Base128{_That} {}
Expand Down
8 changes: 8 additions & 0 deletions tests/std/include/test_header_units_and_modules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,14 @@ void test_random() {
minstd_rand0 lcg;
lcg.discard(9999);
assert(lcg() == 1043618065); // N4868 [rand.predef]/1

#ifndef _MSVC_INTERNAL_TESTING // TRANSITION, VSO-2226569
// Test coverage for GH-4899 "Standard Library Modules: uniform_real_distribution emits
// error C2512: 'std::_Unsigned128': no appropriate default constructor available":
const double val = generate_canonical<double, 53>(lcg);
assert(val >= 0.0);
assert(val < 1.0);
#endif // ^^^ no workaround ^^^
}

void test_ranges() {
Expand Down

0 comments on commit 138e116

Please sign in to comment.