January 10, 2002 value of a condition | ||||
---|---|---|---|---|
| ||||
Hi, According to the C++ standard (6.4 Selection statements [stmt.select]) "the value of a condition that is an expression is the value of the expression, implicitly converted to bool for statements other than switch". But it seems that DM uses the value of the expression implicitly converted to int (the following test-case prints "false"): #include <stdio.h> struct A { inline operator int() { return 0; } inline operator bool() { return true; } }; int main(int argc, char *argv[]) { A a; if (a) { printf("true\n"); return 0; } else { printf("false\n"); return 1; } } bye, Christof |
January 10, 2002 Re: value of a condition | ||||
---|---|---|---|---|
| ||||
Posted in reply to Christof Meerwald | Ok, I'll get it fixed. Thanks for the great bug reports! -Walter "Christof Meerwald" <cmeerw@web.de> wrote in message news:a1k5q7$2v33$1@digitaldaemon.com... > Hi, > > According to the C++ standard (6.4 Selection statements [stmt.select]) "the > value of a condition that is an expression is the value of the expression, implicitly converted to bool for statements other than switch". But it seems > that DM uses the value of the expression implicitly converted to int (the following test-case prints "false"): > > #include <stdio.h> > > struct A > { > inline operator int() > { > return 0; > } > > inline operator bool() > { > return true; > } > }; > > > int main(int argc, char *argv[]) > { > A a; > > if (a) > { > printf("true\n"); > return 0; > } > else > { > printf("false\n"); > return 1; > } > } > > > bye, Christof |
Copyright © 1999-2021 by the D Language Foundation