Commit c612467a authored by Celelibi's avatar Celelibi Committed by Stefan Behnel

Emit an error when typeid() is used outside of C++ mode (GH-3637)

parent d77f79c2
...@@ -10871,7 +10871,10 @@ class TypeidNode(ExprNode): ...@@ -10871,7 +10871,10 @@ class TypeidNode(ExprNode):
typeinfo_entry = typeinfo_module.lookup('type_info') typeinfo_entry = typeinfo_module.lookup('type_info')
return PyrexTypes.CFakeReferenceType(PyrexTypes.c_const_type(typeinfo_entry.type)) return PyrexTypes.CFakeReferenceType(PyrexTypes.c_const_type(typeinfo_entry.type))
cpp_message = 'typeid operator'
def analyse_types(self, env): def analyse_types(self, env):
self.cpp_check(env)
type_info = self.get_type_info_type(env) type_info = self.get_type_info_type(env)
if not type_info: if not type_info:
self.error("The 'libcpp.typeinfo' module must be cimported to use the typeid() operator") self.error("The 'libcpp.typeinfo' module must be cimported to use the typeid() operator")
......
# mode: error
# tag: no-cpp, werror
from cython.operator import typeid
def use_typeid():
cdef int i = 0
print typeid(i) == typeid(i)
cdef cppclass A:
pass
def use_new():
cdef A* x = new A()
def use_del():
cdef A a = A()
cdef A *p = &a
del p
_ERRORS = """
8:10: typeid operator only allowed in c++
8:23: typeid operator only allowed in c++
14:20: Operation only allowed in c++
19:4: Operation only allowed in c++
"""
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