Bug 15781 – [REG2.069] Template type deduction failure with same-type variables with different constness

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-03-09T10:36:00Z
Last change time
2016-03-19T19:27:18Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
jbc.engelen

Comments

Comment #0 by jbc.engelen — 2016-03-09T10:36:47Z
``` struct TypeA { int value; } auto foo(T)(T start, T end) { import std.stdio; writeln(typeid(T)); } void main() { alias Tiep = TypeA; const Tiep a; Tiep b; Tiep c = a; // This is fine foo(c,b); foo(a,b); // This is not fine with DMD 2.069.2 } ``` The code compiles fine with DMD 2.068.2. The code fails to compile with DMD 2.068.2 and DMD 2.070.2: deduce.d(19): Error: template deduce.foo cannot deduce function from argument types !()(const(TypeA), TypeA), candidates are: deduce.d(5): deduce.foo(T)(T start, T end) I believe this is a regression. DMD 2.068.2 deduces T = TypeA (non-const). For `alias Tiep = int;` it compiles with DMD 2.070.2. Also when modifying the code to read `auto foo(T)(const T start, const T end)`. This issue was reported after a brief forum discussion: http://forum.dlang.org/thread/[email protected].
Comment #1 by k.hara.pg — 2016-03-11T13:22:56Z
Comment #2 by k.hara.pg — 2016-03-15T12:25:28Z
(In reply to Johan Engelen from comment #0) > The code compiles fine with DMD 2.068.2. > The code fails to compile with DMD 2.068.2 and DMD 2.070.2: > deduce.d(19): Error: template deduce.foo cannot deduce function from > argument types !()(const(TypeA), TypeA), candidates are: > deduce.d(5): deduce.foo(T)(T start, T end) > > I believe this is a regression. > DMD 2.068.2 deduces T = TypeA (non-const). This is a rejects-valid issue from 2.069, so is a regression. But, the behavior in 2.068 -- T is deduced to TypeA (non-const) -- is not intentional result, because there was order-dependent bug. struct S { int value; } void foo(T)(T a, T b) { pragma(msg, T); } void main() { const S cs; S ms; foo(cs, ms); // prints 'S' foo(ms, cs); // prints 'const(S)', inconsistent! } Therefore, from the built-in common type calculation mechanism, the T should be deduced to const(S) independent from the order of function arguments.
Comment #3 by k.hara.pg — 2016-03-15T12:26:05Z
Comment #4 by github-bugzilla — 2016-03-19T06:37:14Z
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/db7e4e1136a0c4cd1c0e310b0fdbc1984894719f fix Issue 15781 - Template type deduction failure with same-type variables with different constness https://github.com/D-Programming-Language/dmd/commit/cd8e31700a0f97a073087eac4eaf9d58b7f59a7a Merge pull request #5531 from 9rnsr/fix15781 [REG2.069] Issue 15781 - Template type deduction failure with same-type variables with different constness
Comment #5 by github-bugzilla — 2016-03-19T19:27:18Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/db7e4e1136a0c4cd1c0e310b0fdbc1984894719f fix Issue 15781 - Template type deduction failure with same-type variables with different constness https://github.com/D-Programming-Language/dmd/commit/cd8e31700a0f97a073087eac4eaf9d58b7f59a7a Merge pull request #5531 from 9rnsr/fix15781