Thread overview | ||||||
---|---|---|---|---|---|---|
|
February 05, 2008 [Issue 1818] New: storage class in type tuples is discarded for function and delegate declarations | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=1818 Summary: storage class in type tuples is discarded for function and delegate declarations Product: D Version: 2.010 Platform: PC OS/Version: All Status: NEW Keywords: wrong-code, spec Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: kamm-removethis@incasoftware.de Type tuples do contain storage class information when obtained via is(func argstuple == function) or std.traits.ParameterTypeTuple. However, this information is discarded if the tuple is used for a function declaration even though the ParameterTypeTuple retains the storage class sometimes. void foo(ref int i) { ++i; } void bar(ParameterTypeTuple!(foo) f) { foo(f); } void main() { int i = 0; foo(i); bar(i); writefln(i); // prints 1 } // but incorrectly: pragma(msg, ParameterTypeTuple!(foo).stringof); // prints "(ref int)" pragma(msg, ParameterTypeTuple!(bar).stringof); // prints "(ref int)" I think the frontend code responsible for this misbehaviour is func.c around line 760. There the storage class of the tuple is propagated to each of the tuple members, replacing existing storage classes. Fixing this bug will allow compile-time reflection and manipulation of parameter storage classes. It would still be impossible to create type tuples containing non-default storage classes directly, but using code similar to this will allow indirect manipulation via argument tuples: template appendArg(X, T...) { alias ParameterTypeTuple!(void delegate(T, X)) appendArg; } template appendRefArg(X, T...) { alias ParameterTypeTuple!(void delegate(T, ref X)) appendRefArg; } alias appendRefArg!(int) refint; alias appendArg!(real, refint) refint_real; alias appendRefArg!(long, refint_real) refint_real_outlong; pragma(msg, refint.stringof ~ " " ~ refint_real.stringof ~ " " ~ refint_real_outlong.stringof); // current output: (ref int) (int, real) (int, real, ref long) // desired output: (ref int) (ref int, real) (ref int, real, ref long) Consequently this would also allow the implementation of the identity function template that Andrei recommended as a testcase a while back: ReturnType!(func) ident(alias func)(ParameterTypeTuple!(func) args) { return func(args); } Currently this fails for functions with arguments using non-default storage classes. Finally, this change might break some code that expects storage classes to be lost. It also interacts with bugs 1411 and 1424. -- |
February 07, 2008 [Issue 1818] storage class in type tuples is discarded for function and delegate declarations | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1818 ------- Comment #1 from kamm-removethis@incasoftware.de 2008-02-07 13:10 ------- I have commented out the mentioned code in func.c and tested this with gdc. While it works in the sense that void foo(ref int i) { ++i; } void bar(ParameterTypeTuple!(foo) f) { foo(f); } now yields a bar taking a ref int, there are other issues. Most notably template printT(T...) { pragma(msg, T.stringof); alias T printT; } alias printT!(ParameterTypeTuple!(foo)) printed; prints a mere (int). This seems to happen because tuples are split into types when instantiating a template, losing their extra information. (template.c TemplateInstance::semanticTiargs I think). Looking at the whole issue again, it may be more sensible to remove storage class information from type tuples altogether. After all, they are supposed to hold types and not argument-specifications. As storage class manipulation is essential in some instances, a new kind of tuple could be introduced: ArgumentTuple? -- |
June 10, 2011 [Issue 1818] storage class in type tuples is discarded for function and delegate declarations | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1818 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dbiehl@gmx.net --- Comment #2 from yebblies <yebblies@gmail.com> 2011-06-10 10:47:20 PDT --- *** Issue 1424 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 22, 2012 [Issue 1818] storage class in type tuples is discarded for function and delegate declarations | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1818 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bugzilla@digitalmars.com Resolution| |WORKSFORME --- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2012-01-21 21:45:58 PST --- The example now prints: 2 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation