Bug 8669 – TemplateThisParameter should change member function's qualifier

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-16T07:49:00Z
Last change time
2013-03-11T22:06:12Z
Keywords
pull
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2012-09-16T07:49:19Z
With current implementation, a member function with TemplateThisParameter is not generated based on each 'this' type. struct X { void foo(this T)() {} } void main() { X mx; mx.foo(); // T == X, and foo is mutable member function. // then we can call it with mutable object. immutable(X) ix; ix.foo(); // T == immutable(X), but foo is still *mutable* member function. // then we cannot call it with immutable object } foo is always instantiated as mutable member function, and always cannot be called with non-mutable object. I think this is not convenient in many cases. ==== Enhancement: If foo is called from immutable object, foo should be instantiated as immutable member function. Following is detailed explanation of compiler behavior to realize it. The declaration of foo is expanded as like follows. struct X { template foo(this T) { void foo() {} } } If T is immutable type, compiler would wrap the template body into StorageClassDeclaration. struct X { template foo(this T) { // if T == immutable immutable{ // <-- automatically wrapped by the compiler void foo() {} // now foo is immutable member function } } template foo(this T) { // if T == const const{ // <-- automatically wrapped by the compiler void foo() {} // now foo is const member function } } // as well, if T == shared, shared const, inout, and shared inout } This would make forwarding operations more convenient, e.g. std.typecons.Proxy.
Comment #1 by k.hara.pg — 2012-09-16T08:26:21Z
Comment #2 by github-bugzilla — 2013-03-06T09:56:00Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/31e57cd1e1606d156f2117c5bef4701005438fba fix Issue 8669 - TemplateThisParameter should change member function's qualifier https://github.com/D-Programming-Language/dmd/commit/391addfda30738089ca220f0d9f025e3842deb1f Merge pull request #1121 from 9rnsr/fix8669 [enh] Issue 8669 - TemplateThisParameter should change member function's qualifier
Comment #3 by github-bugzilla — 2013-03-11T22:06:12Z
Commit pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/0879a5ea45c08463b3a408f7e29e48ec8312be5b Improve test cases for qualified objects By fixing issue 8669, they are now working properly.