[Issue 15930] New: min/max of pointers violates const

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Apr 15 12:12:11 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=15930

          Issue ID: 15930
           Summary: min/max of pointers violates const
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: schveiguy at yahoo.com

Example (I have to print in a separate function to avoid constant folding):

void foo(const int *x1, const int *x2)
{
    import std.stdio: writeln;
    writeln(*x1, " ", *x2);
}

void main()
{
    import std.stdio: writeln;
    int x1;
    const int x2;

    import std.algorithm: max, min;
    auto v = max(&x1, &x2);
    auto v2 = min(&x1, &x2);
    *v = 5;
    *v2 = 5;
    foo(&x1, &x2);
}

compiles, prints 5 5, showing x2 has been changed.

--


More information about the Digitalmars-d-bugs mailing list