diff --git a/cpp/ast.py b/cpp/ast.py index bc6535f..c713241 100644 --- a/cpp/ast.py +++ b/cpp/ast.py @@ -992,7 +992,7 @@ def _get_method(self, return_type_and_name, modifiers, templated_types, assert token.name == '(', token name = return_type_and_name.pop() - if (len(return_type_and_name) > 2 and + if (len(return_type_and_name) > 1 and (return_type_and_name[-1].name == 'operator' or return_type_and_name[-1].name == '~')): op = return_type_and_name.pop() diff --git a/test_ast.py b/test_ast.py index 8ba5e1b..492c0e1 100755 --- a/test_ast.py +++ b/test_ast.py @@ -702,6 +702,19 @@ def test_destructor(self): body=[]), nodes[0]) + def test_class_operators(self): + for operator in ('=', '+=', '-=', '*=', '==', '!=', '()', '[]', '<', + '>'): + code = 'class Foo { void operator%s(); };' % operator + nodes = list(MakeBuilder(code).generate()) + self.assertEqual(1, len(nodes)) + function = nodes[0].body[0] + expected = Function(('operator%s' % operator), + list(get_tokens('void')), []) + self.assertEqual(expected.return_type, function.return_type) + self.assertEqual(expected, function) + self.assertEqual(Class('Foo', body=[expected]), nodes[0]) + def test_class_virtual_inline_destructor(self): code = 'class Foo { virtual inline ~Foo(); };' nodes = list(MakeBuilder(code).generate())