[Issue 5735] non-scalar types implicitly converted to boolean.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 18 14:31:49 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5735



--- Comment #4 from Walter Bright <bugzilla at digitalmars.com> 2011-04-18 14:28:14 PDT ---
// Suitable for inclusion in test suite

struct A {}

void foo(bool cond){}

void main()
{
    A a;
    int i;

    static assert(!__traits(compiles, assert(a)));      // type A does not have
a boolean value
    static assert(!__traits(compiles, assert(i || a))); // type A does not have
a boolean value
    static assert(!__traits(compiles, assert(0 || a))); // OK

//    if(a) {}        // type A does not have a boolean value
//    if(i || a) {}   // type A does not have a boolean value
//    if(0 || a) {}   // type A does not have a boolean value

    static assert(!__traits(compiles, foo(a)));         // cannot implicitly
convert type A to bool
    static assert(!__traits(compiles, foo(i || a)));    // OK
    static assert(!__traits(compiles, foo(0 || a)));    // OK
}

-- 
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