Bug 15930 – min/max of pointers violates const

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-04-15T19:12:11Z
Last change time
2021-02-17T15:14:49Z
Assigned to
No Owner
Creator
Steven Schveighoffer

Comments

Comment #0 by schveiguy — 2016-04-15T19:12:11Z
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 #1 by n8sh.secondary — 2021-02-17T06:09:34Z
Comment #2 by schveiguy — 2021-02-17T15:14:49Z
Hm... thanks. I wonder if a test case should be added.