Skip to content

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

Description

@statementreply

Describe the bug

Currently, piecewise_constant_distribution<T>::param_type and piecewise_linear_distribution<T>::param_type inherit from discrete_distribution<size_t>::param_type, although conceptually they are unrelated types. piecewise_linear_distribution<T>::param_type even breaks the invariants of its base class.

Invalid code could compile and run unexpectedly, and return nonsense.

Command-line test case

C:\Users\He\source\test>type random_param_inherit.cpp
#include <cstddef>
#include <random>

using namespace std;

int main() {
    piecewise_linear_distribution<> d1;
    discrete_distribution<size_t> d2(d1.param());
    return 0;
}
C:\Users\He\source\test>cl /EHsc /W4 /WX random_param_inherit.cpp
用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.28.29812 版
版权所有(C) Microsoft Corporation。保留所有权利。

random_param_inherit.cpp
Microsoft (R) Incremental Linker Version 14.28.29812.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:random_param_inherit.exe
random_param_inherit.obj

Expected behavior

The test code should not compile.

STL version

https://github.com/microsoft/STL/commit/721e3ad8952fce3447916ecdbff3863043686fa1

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions