Bug 13294 – [IFTI] IFTI fails or works incorrectly for function with const and mutable `ref` parameters of most types

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-08-15T12:15:00Z
Last change time
2014-08-28T04:10:18Z
Keywords
pull, rejects-valid, wrong-code
Assigned to
nobody
Creator
verylonglogin.reg

Comments

Comment #0 by verylonglogin.reg — 2014-08-15T12:15:02Z
This code should compile fine: --- void f(T)(const ref T src, ref T dest) { } void main() { const byte src; byte dest; f(src, dest); } --- main.d(8): Error: template main.f cannot deduce function from argument types !()(const(byte), byte), candidates are: main.d(1): main.f(T)(ref const T src, ref T dest) --- Note: Fails only for `byte`/`ubyte`/`short`/`ushort`.
Comment #1 by verylonglogin.reg — 2014-08-15T12:38:23Z
It's not just these four integral types. For most other types `const` is incorrectly added. This code should compile fine: --- void f(T)(const ref T src, ref T dest) // T is const char here { static assert(!is(T == const)); // fails } void main() { const char src; char dest; f(src, dest); } --- Note: static assert passes for `int`/`uint`/`long`/`ulong` and floating point types.
Comment #2 by verylonglogin.reg — 2014-08-15T12:49:21Z
(In reply to Denis Shelomovskij from comment #1) > For most other types `const` is incorrectly added. And because of CTFE bug 13295 all modifications of such variables disappear, thus in worst case causing nasty wrong-code bugs.
Comment #3 by verylonglogin.reg — 2014-08-15T13:16:59Z
(In reply to Denis Shelomovskij from comment #2) > (In reply to Denis Shelomovskij from comment #1) > > For most other types `const` is incorrectly added. > > And because of CTFE issue 13295 all modifications of such variables disappear, > thus in worst case causing nasty wrong-code bugs. But as some modifications disappear anyway (because of issue 13297) and thus one can't reliably use `ref` in CTFE it's probably isn't that big problem.
Comment #4 by dlang-bugzilla — 2014-08-15T13:56:10Z
Comment #5 by schuetzm — 2014-08-22T10:49:59Z
User Xinok report a problem on the forums, which is probably related to this bug: http://forum.dlang.org/post/[email protected]
Comment #6 by paul.d.anderson — 2014-08-22T22:27:32Z
*** Issue 13351 has been marked as a duplicate of this issue. ***
Comment #7 by verylonglogin.reg — 2014-08-25T07:55:06Z
(In reply to Paul D. Anderson from comment #6) > *** Issue 13351 has been marked as a duplicate of this issue. *** So here is testcase for those issue: --- void f1(T)(in T) { T t; ++t; } void f2(T)(in T, in T) { T t; ++t; } // (line 2) void main() { const double n; f1(n); // ok f2(n, n); // error (line 8) } --- main.d(2): Error: cannot modify const expression nan main.d(8): Error: template instance main.f2!(const(double)) error instantiating --- Compiler carries in case there is more than one argument.
Comment #8 by verylonglogin.reg — 2014-08-25T07:56:11Z
(In reply to Denis Shelomovskij from comment #7) > ...carries in case... *carries `const` in case
Comment #9 by k.hara.pg — 2014-08-25T16:22:16Z
Comment #10 by github-bugzilla — 2014-08-25T20:45:44Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/64df8d8fc573f3109af20bc7822b21e3b5c023bf fix Issue 13294 - [IFTI] IFTI fails or works incorrectly for function with const and mutable `ref` parameters of most types This is more better implementation of enhancement 12290. The first implementation #3353 was incomplete, so sadly it had introduced many IFTI regressions - 12403, 13026, 13180, 13223, and 13294. Eventually I noticed that using typeMerge was wrong. It was the biggest root the regressions. And, the enhancement 13127 was pointless change. Now it is mostly reverted. https://github.com/D-Programming-Language/dmd/commit/a7786fadb495a19364da4aa564e6cccf37224750 Merge pull request #3896 from 9rnsr/fix13294 [REG2.066] Issue 13294 - [IFTI] IFTI fails or works incorrectly for function with const and mutable `ref` parameters of most types
Comment #11 by github-bugzilla — 2014-08-28T04:10:18Z
Commit pushed to 2.066 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/4e327f2aec8167efae7128bad91dc3af760c8c35 Merge pull request #3896 from 9rnsr/fix13294 [REG2.066] Issue 13294 - [IFTI] IFTI fails or works incorrectly for function with const and mutable `ref` parameters of most types