November 11, 2012 [Issue 8995] New: `is(<Type> <Identifier> == function)` creates tuple with parameter storage classes | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=8995 Summary: `is(<Type> <Identifier> == function)` creates tuple with parameter storage classes Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: verylonglogin.reg@gmail.com --- Comment #0 from Denis Shelomovskij <verylonglogin.reg@gmail.com> 2012-11-11 10:28:55 MSK --- Function parameter types tuple retrieved with `IsExpression` contains parameter storage classes unless indexed (slicing remains storage classes). It is not documented that typetuple can contain parameter storage classes so it may lead to unexpected behavior and looks inconsistent because `is(typetuple1 == typetuple2)` is `true` for tuples with different storage classes. --- template TypeTuple(T...) { alias T TypeTuple; } template t(alias func) { static if (is(typeof(func) Args == function)) { static assert(is(Args == TypeTuple!(int, int, int, int))); // passes pragma(msg, "Args: ", Args); // (int, ref int, out int, auto int) pragma(msg, "Args[1..2]: ", Args[1..2]); // (ref int) pragma(msg, "Args[1]: ", Args[1]); // int void g1(Args[0 .. 3]) { } // void(int, ref int, out int) pragma(msg, "typeof(g1): ", typeof(g1)); void g2(Args[3]) { } // void(int) pragma(msg, "typeof(g2): ", typeof(g2)); void g3(Args[3 .. 4]) { } // void(auto ref int), error, line 20 } else static assert(0); } void f(T)(int, ref int, out int, auto ref T) { alias t!f tf; } void main() { int i; f(0, i, i, 0); } --- Compiler output: --- Args: (int, ref int, out int, auto int) Args[1..2]: (ref int) Args[1]: int typeof(g1): void(int, ref int, out int) typeof(g2): void(int) main.d(20): Error: auto can only be used for template function parameters main.d(29): Error: template instance main.t!(f) error instantiating main.d(36): instantiated from here: f!(int) main.d(36): Error: template instance main.f!(int) error instantiating --- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 11, 2012 [Issue 8995] `is(<Type> <Identifier> == function)` creates tuple with parameter storage classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis Shelomovskij | http://d.puremagic.com/issues/show_bug.cgi?id=8995 --- Comment #1 from Denis Shelomovskij <verylonglogin.reg@gmail.com> 2012-11-11 10:34:15 MSK --- Workaround to remove storage classes: --- import std.typetuple; template DeStorage(T) { alias T DeStorage; } alias staticMap!(DeStorage, ArgsWithStorageClasses) Args; --- Note, it it's not documented, that `staticMap` will use indexing (`A[x]`) instead of slicing (`A[x .. x+1]`) and in latter case this workaround will not work so you have to copy/paste `staticMap` with current behavior to you code. -- 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