www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15930] New: min/max of pointers violates const


          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 puremagic.com
          Reporter: schveiguy 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.

Apr 15 2016