Opened 6 years ago
Closed 5 years ago
#551 closed enhancement (fixed)
Cython does not allow ctypedef'ing templated types
Description
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 (), inheritance of templated types can provide a workaround if/when it is implemented.
Change History (6)
comment:1 Changed 6 years ago by haoyu
comment:2 Changed 6 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) else: 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(
comment:3 Changed 6 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.
comment:4 Changed 5 years ago by robertwb
- Milestone changed from 0.14 to 0.14.1
comment:5 Changed 5 years ago by robertwb
- Milestone changed from 0.15 to 0.16
- Owner changed from somebody to robertwb
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
comment:6 Changed 5 years ago by robertwb
- Resolution set to fixed
- Status changed from new to closed
Note: See TracTickets for help on using tickets.
Inheritance of templated types is a separated issue that filed in #552.