From 8baa9dba02ed1cb1576072a0be56325d3c5d5c48 Mon Sep 17 00:00:00 2001 From: Lars Buitinck <larsmans@gmail.com> Date: Sat, 23 Aug 2014 11:59:41 +0200 Subject: [PATCH] fix nested C++ template syntax --- Cython/Compiler/PyrexTypes.py | 4 +--- tests/compile/cpp_templates.pyx | 10 ++++++++++ tests/compile/templates.h | 5 +++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index b24e46eaa..1c1e4e26e 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -3153,10 +3153,8 @@ class CppClassType(CType): if for_display: brackets = "[%s]" else: - brackets = "<%s>" + brackets = "<%s> " templates = brackets % ",".join(template_strings) - if templates[-2:] == ">>": - templates = templates[:-2] + "> >" else: templates = "" if pyrex or for_display: diff --git a/tests/compile/cpp_templates.pyx b/tests/compile/cpp_templates.pyx index 4d37294ca..cab981e38 100644 --- a/tests/compile/cpp_templates.pyx +++ b/tests/compile/cpp_templates.pyx @@ -16,6 +16,8 @@ cdef extern from "templates.h": T getValue1() U getValue2() + void template_function[T](TemplateTest1[T] &) + cdef TemplateTest1[int] a cdef TemplateTest1[int]* b = new TemplateTest1[int]() @@ -39,3 +41,11 @@ cdef TemplateTest1_int aa # Verify that T767 is fixed. cdef public int func(int arg): return arg + +# Regression test: the function call used to produce +# template_function<TemplateTest1<int>>(__pyx_v_t); +# which is valid C++11, but not valid C++98 because the ">>" would be +# parsed as a single token. +cdef public void use_nested_templates(): + cdef TemplateTest1[TemplateTest1[int]] t + template_function(t) diff --git a/tests/compile/templates.h b/tests/compile/templates.h index 7a1391177..31ea9d504 100644 --- a/tests/compile/templates.h +++ b/tests/compile/templates.h @@ -22,4 +22,9 @@ public: U getValue2() { return value2; } }; +template <typename T> +void template_function(TemplateTest1<T> &) +{ +} + #endif -- 2.30.9