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: 3 additions & 8 deletions cpp/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,9 @@ def declaration_to_parts(self, parts, needs_name_removed):
arrayEnd = 0
default = []
other_tokens = []

if parts[0].name == '::':
parts = parts[1:]

# Handle default (initial) values properly.
for i, t in enumerate(parts):
Expand Down Expand Up @@ -1160,14 +1163,8 @@ def _get_return_type_and_class_name(self, token_seq):
# TODO(nnorwitz): if there is only One name like in the
# example above, punt and assume the last bit is the class name.

# Ignore a :: prefix, if exists so we can find the first real name.
i = 0
if token_seq[0].name == '::':
i = 1
# Ignore a :: suffix, if exists.
end = len(token_seq) - 1
if token_seq[end - 1].name == '::':
end -= 1

# Make a copy of the sequence so we can append a sentinel
# value. This is required for get_name will has to have some
Expand All @@ -1184,8 +1181,6 @@ def _get_return_type_and_class_name(self, token_seq):
names.append(new_name)
i += len(new_name)

# Now that we have the names, it's time to undo what we did.

# Remove the sentinel value.
names[-1].pop()
# Flatten the token sequence for the return type.
Expand Down
2 changes: 2 additions & 0 deletions test/template3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
template <typename T>
class Foo* fct(T t);
4 changes: 4 additions & 0 deletions test/template4.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class A;

template <typename T>
::A* B::fn();
5 changes: 5 additions & 0 deletions test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,11 @@ def test_variable_declaration_with_define(self):
self.assertEqual(Function('FOO', list(get_tokens('void')), []),
nodes[2])

def test_template_function(self):
nodes = list(MakeBuilder('template <> void equal<0>();').generate())
self.assertEqual(1, len(nodes))
self.assertEqual(Function('equal', list(get_tokens('void')), [], templated_types={}), nodes[0])


if __name__ == '__main__':
unittest.main()