[Issue 9091] New: Perhaps another forward referencing bug.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Nov 28 04:08:32 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9091
Summary: Perhaps another forward referencing bug.
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: turkeyman at gmail.com
--- Comment #0 from Manu <turkeyman at gmail.com> 2012-11-28 04:08:31 PST ---
I've created a new bug from this thread:
http://d.puremagic.com/issues/show_bug.cgi?id=9065
That thread has forked into unrelated conversations, and I suspect this is a
separate bug anyway...
Kenji: I boiled this down as much as I could...
class Test
{
void func()
{
void templateFunc( T )( ref const T obj )
{
foreach( m; __traits( allMembers, T ) )
{
pragma(msg, m);
static if( isVariable!( __traits(getMember, T, m) ) )
{
//...
}
}
}
templateFunc( this );
}
// some class members
int x;
}
isVariable throws lots of errors when considering the class members.
Note:
__traits(allMembers, T) and __traits(getMember, T, m)
These should also work with class instances, not just types, eg:
__traits(allMembers, obj) and __traits(getMember, obj, m)
And these combinations should also work:
__traits(allMembers, T) and __traits(getMember, obj, m)
__traits(allMembers, obj) and __traits(getMember, T, m)
All these configurations throw errors, and the errors are different for each
configuration.
Depends on:
/**
* Detect whether symbol or type $(D X) is a function.
*/
template isFunction(X...) if (X.length == 1)
{
static if (is(typeof(&X[0]) U : U*) && is(U == function) ||
is(typeof(&X[0]) U == delegate))
{
// x is a (nested) function symbol.
enum isFunction = true;
}
else static if (is(X[0] T))
{
// x is a type. Take the type of it and examine.
enum isFunction = is(T == function);
}
else
enum isFunction = false;
}
/**
* Detect whether symbol $(D X) is a run-time variable.
*/
template isVariable(X...) if (X.length == 1)
{
static if (!is(X[0]) &&
!is(typeof(X[0]) == void) &&
!isFunction!(X[0]))
{
enum isVariable =
is(typeof({ auto ptr = &X[0]; }))
|| is(typeof({ enum off = X[0].offsetof; }));
}
else
enum isVariable = false;
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list