diff options
author | Lars Buitinck <larsmans@gmail.com> | 2014-08-23 11:59:41 +0200 |
---|---|---|
committer | Lars Buitinck <larsmans@gmail.com> | 2014-08-23 12:03:46 +0200 |
commit | 8baa9dba02ed1cb1576072a0be56325d3c5d5c48 (patch) | |
tree | 7f0a435b22658f48a18865a79034bba74aade5c6 | |
parent | 07c422a5e4623fc21f672538ca2a953bdbc04cf4 (diff) | |
download | cython-8baa9dba02ed1cb1576072a0be56325d3c5d5c48.tar.gz |
fix nested C++ template syntax
-rw-r--r-- | Cython/Compiler/PyrexTypes.py | 4 | ||||
-rw-r--r-- | tests/compile/cpp_templates.pyx | 10 | ||||
-rw-r--r-- | 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 |