Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 13 additions & 0 deletions test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down