Bug 9416 – [REG][2.060 -> 02.061] DMD eagerly instantiates template parameter-less opAssign

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-01-28T05:48:00Z
Last change time
2013-01-31T04:45:24Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
monarchdodra

Comments

Comment #0 by monarchdodra — 2013-01-28T05:48:01Z
Regression from 2.060: No matter what, when given an template but parameter less opAssign that takes a typeof(this) (or a type explicitly castable to typeof(this)), dmd will try to instantiate it. Here is a clearer explanation in the form of a reduced test case. //---- struct S { void bar()(S) { static assert(0); //Fine } void opAssign()(int) { static assert(0); //Fine } void opAssign()(S) { static assert(0); //main.d(13): Error: static assert (0) is false //main.d(2): instantiated from here: opAssign!() } } void main() {} //---- Expected behavior should be: No error unless opAssign is called (It isn't). This is problematic for template structs that use this scheme for "poor man's SFINAE", or who template functions just so that the compiler can guess the correct "nothrowness" of said function. For example: std.typecons.Nullable: //---- import std.typecons; void main() { Nullable!(immutable int) s; } //---- 2.060: Fine 2.061: src\phobos\std\typecons.d(1170): Error: can only initialize const member _value inside constructor //Inside std.typecons.Nullable: void opAssign()(T value) { _value = value; //HERE _isNull = false; }
Comment #1 by k.hara.pg — 2013-01-30T20:19:14Z
Comment #2 by github-bugzilla — 2013-01-31T01:47:30Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/ca03c609211952f9640d38531dd4f282cedc22ac fix Issue 9416 - [REG][2.060 -> 02.061] DMD eagerly instantiates template parameter-less opAssign https://github.com/D-Programming-Language/dmd/commit/b94fd3b7d2164ef1fc924265d4c5d04c7c673463 Merge pull request #1585 from 9rnsr/fix_assign Issue 9258 & 9404 & 9416 - fix regressions around opAssign