Ticket #551 (closed enhancement: fixed)

Opened 4 years ago

Last modified 3 years ago

Cython does not allow ctypedef'ing templated types

Reported by: tokidoki Owned by: robertwb
Priority: major Milestone: 0.16
Component: C++ Keywords:


Cython raises a syntax error when ctypedef'ing a templated type.

For example, the following code:

from libcpp.vector import vector
ctypedef vector[int] VectOfInt

raises the following Syntax Error:

ctypedef vector[int] VectOfInt
/home/toki/progs/cython13tests/bug6.pyx:3:21: Syntax error in ctypedef statement

As pointed out by Haoyu BAI ( http://codespeak.net/pipermail/cython-dev/2010-July/009126.html), inheritance of templated types can provide a workaround if/when it is implemented.

Change History

Changed 4 years ago by haoyu

Inheritance of templated types is a separated issue that filed in #552.

Changed 4 years ago by haoyu

The following patch that removes two lines of code would "enable" this feature. Though I don't understand what these code are checking for.

diff -r f9703a7c50c3 Cython/Compiler/Parsing.py
--- a/Cython/Compiler/Parsing.py	Fri May 14 18:56:22 2010 +0800
+++ b/Cython/Compiler/Parsing.py	Mon Jul 05 15:08:36 2010 +0800
@@ -2465,8 +2465,6 @@
             return p_c_struct_or_union_definition(s, pos, ctx)
         base_type = p_c_base_type(s, nonempty = 1)
-        if base_type.name is None:
-            s.error("Syntax error in ctypedef statement")
         declarator = p_c_declarator(s, ctx, is_type = 1, nonempty = 1)
         s.expect_newline("Syntax error in ctypedef statement")
         return Nodes.CTypeDefNode(

Changed 4 years ago by robertwb

  • milestone changed from 0.13 to 0.13.1

I'm not positive either--it'll take some more investigation to be sure it's safe to remove though.

Changed 4 years ago by robertwb

  • milestone changed from 0.14 to 0.14.1

Changed 3 years ago by robertwb

  • owner changed from somebody to robertwb
  • milestone changed from 0.15 to 0.16

Apparently it's there to force you to write

ctypedef double point[3]

in the brain-dead C way rather than

ctypedef double[3] point

Changed 3 years ago by robertwb

  • status changed from new to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.