Commit 4a57c2c3 authored by Stefan Behnel's avatar Stefan Behnel

declare C++ default constructor 'except +', fix constructor declarations in test

parent 66204a91
...@@ -1329,7 +1329,7 @@ class NewExprNode(AtomicExprNode): ...@@ -1329,7 +1329,7 @@ class NewExprNode(AtomicExprNode):
self.cpp_check(env) self.cpp_check(env)
constructor = type.scope.lookup(u'<init>') constructor = type.scope.lookup(u'<init>')
if constructor is None: if constructor is None:
return_type = PyrexTypes.CFuncType(type, []) return_type = PyrexTypes.CFuncType(type, [], exception_check='+')
return_type = PyrexTypes.CPtrType(return_type) return_type = PyrexTypes.CPtrType(return_type)
type.scope.declare_cfunction(u'<init>', return_type, self.pos) type.scope.declare_cfunction(u'<init>', return_type, self.pos)
constructor = type.scope.lookup(u'<init>') constructor = type.scope.lookup(u'<init>')
......
...@@ -7,19 +7,19 @@ cdef extern from "shapes.h" namespace "shapes": ...@@ -7,19 +7,19 @@ cdef extern from "shapes.h" namespace "shapes":
cdef cppclass Circle(Shape): cdef cppclass Circle(Shape):
int radius int radius
Circle(int) Circle(int) except +
cdef cppclass Rectangle(Shape): cdef cppclass Rectangle(Shape):
int width int width
int height int height
Rectangle() Rectangle() except +
Rectangle(int, int) Rectangle(int, int) except +
int method(int) int method(int)
int method(bint) int method(bint)
cdef cppclass Square(Rectangle): cdef cppclass Square(Rectangle):
int side int side
Square(int) Square(int) except +
cdef cppclass Empty(Shape): cdef cppclass Empty(Shape):
pass pass
...@@ -39,6 +39,17 @@ def test_new_del(): ...@@ -39,6 +39,17 @@ def test_new_del():
del rect, circ del rect, circ
print constructor_count-c, destructor_count-d print constructor_count-c, destructor_count-d
def test_default_constructor():
"""
>>> test_default_constructor()
0.0
"""
shape = new Empty()
try:
return shape.area()
finally:
del shape
def test_rect_area(w, h): def test_rect_area(w, h):
""" """
>>> test_rect_area(3, 4) >>> test_rect_area(3, 4)
......
...@@ -49,6 +49,7 @@ namespace shapes { ...@@ -49,6 +49,7 @@ namespace shapes {
}; };
class Empty : public Shape { class Empty : public Shape {
public:
float area() { return 0; } float area() { return 0; }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment