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
11 changes: 5 additions & 6 deletions cpp/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,12 +984,11 @@ 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
return_type_and_name[-1].name == 'operator'
):
if (len(return_type_and_name) > 2 and
(return_type_and_name[-1].name == 'operator' or
return_type_and_name[-1].name == '~')):
op = return_type_and_name.pop()
name = tokenize.Token(tokenize.NAME, 'operator' + name.name,
name = tokenize.Token(tokenize.NAME, op.name + name.name,
op.start, name.end)
# Handle templatized ctors.
elif name.name == '>':
Expand Down Expand Up @@ -1125,7 +1124,7 @@ def _get_method(self, return_type_and_name, modifiers, templated_types,
raise ParseError((token, return_type_and_name, parameters))

# Looks like we got a method, not a function.
if len(return_type) > 2 and return_type[-1].name == '::':
if len(return_type) > 1 and return_type[-1].name == '::':
return_type, in_class = \
self._get_return_type_and_class_name(return_type)
return Method(indices.start, indices.end, name.name, in_class,
Expand Down
12 changes: 12 additions & 0 deletions test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,18 @@ def test_class_virtual_inheritance_reverse(self):
self.assertEqual(1, len(nodes))
self.assertEqual(Class('Foo', bases=[Type('Bar')], body=[]), nodes[0])

def test_constructor(self):
code = 'Foo::Foo() {}'
nodes = list(MakeBuilder(code).generate())
self.assertEqual(1, len(nodes))
self.assertEqual(Method('Foo', list(get_tokens('Foo')), [], [], body=[]), nodes[0])

def test_destructor(self):
code = 'Foo::~Foo() {}'
nodes = list(MakeBuilder(code).generate())
self.assertEqual(1, len(nodes))
self.assertEqual(Method('~Foo', list(get_tokens('Foo')), [], [], body=[]), nodes[0])

def test_class_virtual_inline_destructor(self):
code = 'class Foo { virtual inline ~Foo(); };'
nodes = list(MakeBuilder(code).generate())
Expand Down