Standard Library Modules: Add compiler workarounds for <random> by StephanTLavavej · Pull Request #4906 · microsoft/STL (original) (raw)

Fixes #4899 by adding workarounds for DevCom-10729775.

I slightly reduced the test case from uniform_real_distribution, then verified that the generate_canonical test coverage fails without the workaround (for both Standard Library Modules and Standard Library Header Units), before passing with the workaround.

_Signed128 has the same code pattern, and I was able to craft a highly contrived repro demonstrating that it needs the same workaround. I don't think we need to add automated test coverage for it, though.

Click to expand bonus repro:

C:\Temp>"C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Auxiliary\Build\vcvarsall.bat" x64
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.12.0-pre.1.0
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

C:\Temp>type meow.cpp

import std; using namespace std;

constexpr long long meow() { const auto v = views::iota(0ll, 1729ll); const auto b = ranges::begin(v); const auto e = ranges::end(v); return static_cast(e - b); }

int main() { constexpr long long value = meow(); static_assert(value == 1729ll); }

C:\Temp>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od /c "%VCToolsInstallDir%\modules\std.ixx"
std.ixx

C:\Temp>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od meow.cpp std.obj
meow.cpp
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.42.34226\include\__msvc_int128.hpp(1184): error C2512: 'std::_Signed128': no appropriate default constructor available
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.42.34226\include\ranges(887): note: while evaluating constexpr function 'std::operator -'
meow.cpp(8): note: while evaluating constexpr function 'std::ranges::operator -'
meow.cpp(12): note: while evaluating constexpr function 'meow'
meow.cpp(12): error C2131: expression did not evaluate to a constant
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.42.34226\include\__msvc_int128.hpp(1184): note: a non-constant (sub-)expression was encountered
meow.cpp(13): error C2131: expression did not evaluate to a constant
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.42.34226\include\__msvc_int128.hpp(1184): note: a non-constant (sub-)expression was encountered