Commit 4610ff37 authored by Xavier Thompson's avatar Xavier Thompson

Detect const-overloading of cypclass methods

parent c32a402e
......@@ -3160,6 +3160,27 @@ class CFuncType(CType):
return 0
return 1
def same_ptr_args_without_cv_with(self, other_type, as_cmethod = 0):
return self.same_ptr_args_without_cv_with_resolved_type(other_type.resolve(), as_cmethod)
def same_ptr_args_without_cv_with_resolved_type(self, other_type, as_cmethod = 0):
if other_type is error_type:
return 1
if not other_type.is_cfunction:
return 0
nargs = len(self.args)
if nargs != len(other_type.args):
return 0
for i in range(as_cmethod, nargs):
if not ptr_to_same_without_cv(self.args[i].type, other_type.args[i].type):
if not self.args[i].type.same_as(other_type.args[i].type):
return 0
if self.has_varargs != other_type.has_varargs:
return 0
if self.optional_arg_count != other_type.optional_arg_count:
return 0
return 1
def narrower_or_larger_arguments_than(self, other_type, as_cmethod = 0):
return self.narrower_or_larger_arguments_than_resolved_type(other_type.resolve(), as_cmethod)
......@@ -5539,6 +5560,23 @@ def ptr_to_subtype_of(type1, type2):
return type1.base_type.subtype_of(type2.base_type)
return 0
def ptr_to_same_without_cv(type1, type2):
if type1.is_cyp_class and type2.is_cyp_class:
if type1.is_const_cyp_class:
type1 = type1.const_base_type
if type2.is_const_cyp_class:
type2 = type2.const_base_type
return same_type(type1, type2)
elif type1.is_ptr and type2.is_ptr:
type1 = type1.base_type
type1 = type2.base_type
if type1.is_cv_qualified:
type1 = type1.base_type
if type2.is_cv_qualified:
type2 = type2.base_type
return same_type(type1, type2)
return 0
def typecast(to_type, from_type, expr_code):
# Return expr_code cast to a C type which can be
# assigned to to_type, assuming its existing C type
......
......@@ -547,6 +547,12 @@ class Scope(object):
cpp_override_allowed = True
continue
# allow const overloads
if alt_type.is_const_method != type.is_const_method:
error(pos, "Cypclass method const-overloads another method: not supported yet")
cpp_override_allowed = True
continue
elif alt_entry.is_inherited:
# if the arguments are compatible, then the signatures need to actually be the
......@@ -579,6 +585,10 @@ class Scope(object):
# stop if cpp_override_allowed is False for the current alternative
break
# allow const overloads
elif type.same_ptr_args_without_cv_with(alt_type):
error(pos, "Cypclass method const-overloads another method: not supported yet")
# if an overloaded alternative has narrower argument types than another, then the method
# actually called will depend on the static type of the arguments
# we actually also disallow methods where each argument is either narrower or larger
......
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