www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Unable to test for function name

reply "Janice Caron" <caron800 googlemail.com> writes:
This no longer works in D2.008.

    struct A
    {
        void f() {}

        static assert(is(f));
    }

    void main()
    {
        A a;
    }

Under D2.007, the static assert would pass, because f exists. In
D2.008, the static assert fails. Why?

More importantly, how do I test that a function exists in D2.008?
Nov 30 2007
parent reply "Stewart Gordon" <smjg_1998 yahoo.com> writes:
"Janice Caron" <caron800 googlemail.com> wrote in message 
news:mailman.195.1196435027.2338.digitalmars-d puremagic.com...
 This no longer works in D2.008.

    struct A
    {
        void f() {}

        static assert(is(f));
    }
<snip>
 Under D2.007, the static assert would pass, because f exists.
Because f exits? How did you come to that conclusion? I thought the halting problem was unsolvable.
 In D2.008, the static assert fails. Why?
Because a bug has been fixed. To evaluate to true, IsExpression requires that its operand is a semantically valid _type_.
 More importantly, how do I test that a function exists in D2.008?
static assert(is(typeof(f) == function)); (tested only on 1.023 and 2.007 to date) Stewart. -- My e-mail address is valid but not my primary mailbox. Please keep replies on the 'group where everybody may benefit.
Nov 30 2007
parent reply Matti Niemenmaa <see_signature for.real.address> writes:
Stewart Gordon wrote:
 Under D2.007, the static assert would pass, because f exists.
Because f exits? How did you come to that conclusion? I thought the halting problem was unsolvable.
Exists, not exits.
 In D2.008, the static assert fails. Why?
Because a bug has been fixed. To evaluate to true, IsExpression requires that its operand is a semantically valid _type_.
 More importantly, how do I test that a function exists in D2.008?
static assert(is(typeof(f) == function));
static assert (is(typeof(f)); should suffice. -- E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi
Nov 30 2007
parent "Stewart Gordon" <smjg_1998 yahoo.com> writes:
"Matti Niemenmaa" <see_signature for.real.address> wrote in message 
news:fipf8u$2ro$1 digitalmars.com...
 Stewart Gordon wrote:
 Under D2.007, the static assert would pass, because f exists.
Because f exits? How did you come to that conclusion? I thought the halting problem was unsolvable.
Exists, not exits.
Oops. <snip>
 More importantly, how do I test that a function exists in D2.008?
static assert(is(typeof(f) == function));
static assert (is(typeof(f)); should suffice.
That depends on whether it should be allowed that f exists but isn't a function. Stewart. -- My e-mail address is valid but not my primary mailbox. Please keep replies on the 'group where everybody may benefit.
Dec 06 2007