-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
int to bool conversion #117
Comments
I'm not striving to match C++ behavior. The test fails because the types are different. The implicit cast from int to bool and vice versa is inherently dangerous and allows for some syntax I do not want to support. Like abusing it for if-then else assignments:
Your solution will work but for the time being i do not want to allow it. |
Thanks for clarification. But in type-strict environment func f1 which returns type mup::bool_type and the value false should throw also something like 'incomparable types: boolean and int' with the expression: f1()==0 In that case the return value (0) for m_Value (Value) is wrong. |
The test will return false if the types differ. This may not be expected and is indeed inconsistent. I will fix it. |
I get an conversion exception when using functions which are returning int in conjunction with 'and' or 'or'.
From C++11:
When any scalar value is converted to bool, the result is 0 if the value compares equal to 0; otherwise, the result is 1.
I could solve the problem by disabling CheckType for Value::GetBool().
bool Value::GetBool() const
{
//CheckType('b');
return m_val.real() == 1;
}
or
bool Value::GetBool() const
{
if (m_cType != 'b')
{
return ((bool)m_val.real()) == 1;
}
}
The text was updated successfully, but these errors were encountered: