Skip to content

Commit 4ca85bf

Browse files
Fabio AndereggJordanL8
authored andcommitted
always ignore move assignment if there is both copy and move
1 parent ee7531c commit 4ca85bf

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/Generator/Passes/CheckAmbiguousFunctions.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,43 @@ public override bool VisitFunctionDecl(AST.Function function)
6969

7070
private bool CheckDefaultParametersForAmbiguity(Function function, Function overload)
7171
{
72+
// detect if function and overload are copy assignment or move assignment operators
73+
// if both are either one of those types, ignore move assignment operator
74+
if (function.OperatorKind == CXXOperatorKind.Equal && overload.OperatorKind == CXXOperatorKind.Equal &&
75+
function.Parameters.Count == 1 && overload.Parameters.Count == 1)
76+
{
77+
var functionParamType = function.Parameters[0].Type;
78+
var overloadParamType = overload.Parameters[0].Type;
79+
80+
if (functionParamType is PointerType && overloadParamType is PointerType)
81+
{
82+
var functionParamPointerType = functionParamType as PointerType;
83+
var overloadParamPointerType = overloadParamType as PointerType;
84+
85+
var functionPointee = functionParamPointerType.GetPointee();
86+
var overloadPointee = overloadParamPointerType.GetPointee();
87+
88+
functionPointee.TryGetClass(out Class @functionPointeeClass);
89+
overloadPointee.TryGetClass(out Class @overloadPointeeClass);
90+
91+
if (functionPointeeClass == function.Namespace && @overloadPointeeClass == overload.Namespace)
92+
{
93+
if (functionParamPointerType.Modifier == PointerType.TypeModifier.RVReference &&
94+
overloadParamPointerType.Modifier == PointerType.TypeModifier.LVReference)
95+
{
96+
function.ExplicitlyIgnore();
97+
return true;
98+
}
99+
else if (functionParamPointerType.Modifier == PointerType.TypeModifier.LVReference &&
100+
overloadParamPointerType.Modifier == PointerType.TypeModifier.RVReference)
101+
{
102+
overload.ExplicitlyIgnore();
103+
return true;
104+
}
105+
}
106+
}
107+
}
108+
72109
List<Parameter> functionParams = RemoveOperatorParams(function);
73110
List<Parameter> overloadParams = RemoveOperatorParams(overload);
74111

0 commit comments

Comments
 (0)