Reflection to detect public/private/etc?
Nick Sabalausky
a at a.a
Fri Aug 12 14:49:57 PDT 2011
"Nick Sabalausky" <a at a.a> wrote in message
news:j246df$2ael$1 at digitalmars.com...
> "Adam D. Ruppe" <destructionator at gmail.com> wrote in message
> news:j242up$24so$1 at digitalmars.com...
>> There's no way I've found, aside from direct access (so not via
>> getMembers) and seeing it it fails to compile.
>>
>
> I just gave it a try. I think I may be hitting against a bug in
> __traits(compiles) WRT private. This is the best I could get (Using DMD
> 2.054, Win):
>
>
> Note that "auto y = &(foo.d);" fails to compile as expected, but
> __traits(compiles) claims that should compile. It works for the
> non-function members though.
>
> I did the "auto x = &(...);" trick so I wouldn't have to deal with the
> function's params. Maybe you know how to put dummy args in and make it an
> actual function call instead of taking the func's address? That's probably
> be a pain, but maybe it would get around the bug.
>
Oops, I misread the line number. The line "auto y = &(foo.d);" DOES compile.
So it's not a bug in __traits(compiles). But it may simply be a bug in
private. In other words: Taking the address of a private member function
(from some other module) is currently allowed (but seems wrong to me). If
that's fixed, then my code *should* work. But private has practically never
worked anyway :(
More information about the Digitalmars-d-learn
mailing list