Issue 52906
Summary std::lognormal_distribution can overwrite const memory
Labels libc++
Assignees Quuxplusone
Reporter Quuxplusone
    ```
#include <cassert>
#include <random>

int main() {
    typedef std::lognormal_distribution<> D;
    typedef D::param_type P;
    typedef std::mt19937 G;
    G g;
    D d;

    const P p1 = d.param();
    const P p2 = d.param();
    assert(p1 == p2);
    double r1 = d(g, p1); // This line must not modify p1.
    assert(p1 == p2);
}
```
libc++ fails the final `assert`, because `D::param_type` secretly contains a whole `normal_distribution` object(!) and then `d(g, p1)` secretly contains a `const_cast` so it can call that `normal_distribution`'s `operator()`.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to