diff options
-rw-r--r-- | examples/c-to-c.py | 12 | ||||
-rw-r--r-- | examples/tests/test_c-to-c.py | 9 |
2 files changed, 20 insertions, 1 deletions
diff --git a/examples/c-to-c.py b/examples/c-to-c.py index ec2f04b..713cdd3 100644 --- a/examples/c-to-c.py +++ b/examples/c-to-c.py @@ -70,6 +70,10 @@ class CGenerator(object): operand = self._parenthesize_unless_simple(n.expr) if n.op == 'p++': return '%s++' % operand + elif n.op == 'sizeof': + # Always parenthesize the argument of sizeof since it can be + # a name. + return 'sizeof(%s)' % self.visit(n.expr) else: return '%s%s' % (n.op, operand) @@ -401,7 +405,13 @@ def translate_to_c(filename): def zz_test_translate(): # internal use src = r''' -int main(){} ''' +int main(void) +{ + unsigned size; + size = sizeof(size); + return 0; +} +''' parser = c_parser.CParser() ast = parser.parse(src) ast.show() diff --git a/examples/tests/test_c-to-c.py b/examples/tests/test_c-to-c.py index eae0cce..83cc099 100644 --- a/examples/tests/test_c-to-c.py +++ b/examples/tests/test_c-to-c.py @@ -78,6 +78,15 @@ class TestCtoC(unittest.TestCase): int main() {
}''')
+ def test_issue37(self):
+ self._assert_ctoc_correct(r'''
+ int main(void)
+ {
+ unsigned size;
+ size = sizeof(size);
+ return 0;
+ }''')
+
if __name__ == "__main__":
|