Commit beb42251 authored by Stefan Behnel's avatar Stefan Behnel

always convert C integer values to 1/0 when testing them for their boolean value

parent c6d6d842
......@@ -744,13 +744,12 @@ class ExprNode(Node):
constant_result=bool_value)
type = self.type
if type.is_pyobject or type.is_ptr or type.is_float:
if type.is_enum or type.is_error:
return self
elif type.is_pyobject or type.is_int or type.is_ptr or type.is_float:
return CoerceToBooleanNode(self, env)
else:
if not (type.is_int or type.is_enum or type.is_error):
error(self.pos,
"Type '%s' not acceptable as a boolean" % type)
return self
error(self.pos, "Type '%s' not acceptable as a boolean" % type)
def coerce_to_integer(self, env):
# If not already some C integer type, coerce to longint.
......
......@@ -111,3 +111,25 @@ def x_and_1_or_False(x):
False
"""
return x and 1 or False
def test_large_int(unsigned long x):
"""
>>> try: test_large_int(1 << 127)
... except OverflowError: print True
True
>>> try: test_large_int(1 << 63)
... except OverflowError: print True
True
>>> try: test_large_int(1 << 48)
... except OverflowError: print True
True
>>> try: test_large_int(1 << 31)
... except OverflowError: print True
True
>>> test_large_int(0)
False
"""
if True and x:
return True
else:
return False
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment