Is this actually supposed to be legal?
Jonathan M Davis
jmdavisProg at gmx.com
Tue Jul 17 16:37:52 PDT 2012
On Tuesday, July 17, 2012 23:11:43 Timon Gehr wrote:
> This issue is unrelated to CRTP. (also, you probably want to negate
> that static if condition, otherwise the code is valid and poses no
> challenge to a compiler.)
It's not that it makes the compiler's life hard. It's the fact that
conditional compilation relies on state that doesn't exist yet. It's messed up
to be checking whether an object defines something when you're in the middle of
defining that object.
Now, as David N. points out in another post, this isn't exactly the only case
of that. You can make a templated type do it to itself via something like
__traits(derivedMembers, typeof(this)), but in this case, you're doing it on a
template argument which may or may not be a derived class (though presumably
is).
So, in any case, it's a problem in that you do have to be careful about doing
conditional compilation based on the type, since it's in the middle of being
defined, but that's not necessarily enough to merit getting rid of the feature
(especially since you can have essentially the same problem even without a
base class).
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list