diff --git a/cpp/ast.py b/cpp/ast.py index 7ccd146..9dade56 100644 --- a/cpp/ast.py +++ b/cpp/ast.py @@ -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): @@ -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 @@ -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. diff --git a/test/template3.h b/test/template3.h new file mode 100644 index 0000000..af93acb --- /dev/null +++ b/test/template3.h @@ -0,0 +1,2 @@ +template +class Foo* fct(T t); diff --git a/test/template4.h b/test/template4.h new file mode 100644 index 0000000..5b4055d --- /dev/null +++ b/test/template4.h @@ -0,0 +1,4 @@ +class A; + +template +::A* B::fn(); diff --git a/test_ast.py b/test_ast.py index 237a408..392b31b 100755 --- a/test_ast.py +++ b/test_ast.py @@ -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()