D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15930 - min/max of pointers violates const
Summary: min/max of pointers violates const
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-15 19:12 UTC by Steven Schveighoffer
Modified: 2021-02-17 15:14 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Steven Schveighoffer 2016-04-15 19:12:11 UTC
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.
Comment 2 Steven Schveighoffer 2021-02-17 15:14:49 UTC
Hm... thanks. I wonder if a test case should be added.