Skip to content

Conversation

@frederick-vs-ja
Copy link
Contributor

By changing the discrete_distribution<size_t> base class subobjects to leading member subobjects. This doesn't change layout of the piecewise_{constant,linear}_distribution objects as said in the comments. Also do this for their param_type.

This results in API breakages but is probably safe for ABI.

Fixes #1600.

@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner January 21, 2026 06:30
@github-project-automation github-project-automation bot moved this to Initial Review in STL Code Reviews Jan 21, 2026
@StephanTLavavej StephanTLavavej added the bug Something isn't working label Jan 21, 2026
@github-project-automation github-project-automation bot moved this from Initial Review to Work In Progress in STL Code Reviews Jan 21, 2026
@StephanTLavavej StephanTLavavej moved this from Work In Progress to Initial Review in STL Code Reviews Jan 26, 2026
@StephanTLavavej StephanTLavavej self-assigned this Jan 26, 2026
@StephanTLavavej StephanTLavavej removed their assignment Jan 30, 2026
@StephanTLavavej StephanTLavavej moved this from Initial Review to Ready To Merge in STL Code Reviews Jan 30, 2026
@StephanTLavavej
Copy link
Member

Thank you, this is great!! 😻 I pushed minor changes.

Importantly, I manually compared old vs. new for debug/release x64/x86, verifying not only the sizeof and alignof but that the layouts were effectively identical after the base class surgery. This is the same technique that I used for my previous <random> layout overhauls.

#include <print>
#include <random>
#include <string_view>
using namespace std;

template <typename T>
void test(const string_view name) {
    println("sizeof({}): {}", name, sizeof(T));
    println("alignof({}): {}", name, alignof(T));
}

int main() {
#ifdef _DEBUG
    println("Debug; {}-bit; _MSVC_STL_UPDATE: {}", sizeof(void*) * 8, _MSVC_STL_UPDATE);
#else
    println("Release; {}-bit; _MSVC_STL_UPDATE: {}", sizeof(void*) * 8, _MSVC_STL_UPDATE);
#endif
    test<piecewise_constant_distribution<float>>("piecewise_constant_distribution<float>");
    test<piecewise_constant_distribution<double>>("piecewise_constant_distribution<double>");
    test<piecewise_constant_distribution<float>::param_type>("piecewise_constant_distribution<float>::param_type");
    test<piecewise_constant_distribution<double>::param_type>("piecewise_constant_distribution<double>::param_type");
    test<piecewise_linear_distribution<float>>("piecewise_linear_distribution<float>");
    test<piecewise_linear_distribution<double>>("piecewise_linear_distribution<double>");
    test<piecewise_linear_distribution<float>::param_type>("piecewise_linear_distribution<float>::param_type");
    test<piecewise_linear_distribution<double>::param_type>("piecewise_linear_distribution<double>::param_type");
}

struct Meow1 : piecewise_constant_distribution<float> {};
struct Meow2 : piecewise_constant_distribution<double> {};
struct Meow3 : piecewise_constant_distribution<float>::param_type {};
struct Meow4 : piecewise_constant_distribution<double>::param_type {};
struct Meow5 : piecewise_linear_distribution<float> {};
struct Meow6 : piecewise_linear_distribution<double> {};
struct Meow7 : piecewise_linear_distribution<float>::param_type {};
struct Meow8 : piecewise_linear_distribution<double>::param_type {};
cl /EHsc /nologo /W4 /std:c++latest /MTd /Od /d1reportSingleClassLayoutMeow meow.cpp && meow
cl /EHsc /nologo /W4 /std:c++latest /MT /Od /d1reportSingleClassLayoutMeow meow.cpp && meow

@StephanTLavavej StephanTLavavej moved this from Ready To Merge to Merging in STL Code Reviews Jan 30, 2026
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Merging

Development

Successfully merging this pull request may close these issues.

<random>: piecewise_linear_distribution<T>::param_type should not inherit from discrete_distribution<size_t>::param_type

2 participants