Skip to content

Commit 4adc3d6

Browse files
committed
Fixed right-value references creating ambiguous overloads.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 202ae75 commit 4adc3d6

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

src/AST/Type.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public override bool Equals(object obj)
356356
var type = obj as PointerType;
357357
if (type == null) return false;
358358

359-
return Pointee.Equals(type.Pointee)
359+
return QualifiedPointee.Equals(type.QualifiedPointee)
360360
&& Modifier == type.Modifier;
361361
}
362362

src/Generator/Passes/CheckAmbiguousFunctions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ private bool CheckDefaultParametersForAmbiguity(Function function, Function over
7676
AST.Type funcType = GetFinalType(function.Parameters[i]);
7777
AST.Type overloadType = GetFinalType(overload.Parameters[i]);
7878

79-
if (!funcType.Equals(overloadType))
79+
AST.Type funcPointee = funcType.GetFinalPointee() ?? funcType;
80+
AST.Type overloadPointee = overloadType.GetFinalPointee() ?? overloadType;
81+
82+
if (((funcPointee.IsPrimitiveType() || overloadPointee.IsPrimitiveType()) &&
83+
!funcType.Equals(overloadType)) ||
84+
!funcPointee.Equals(overloadPointee))
8085
return false;
8186
}
8287

tests/Common/Common.Tests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ public void TestCodeGeneration()
2727

2828
using (var hasOverloadsWithDifferentPointerKindsToSameType =
2929
new HasOverloadsWithDifferentPointerKindsToSameType())
30+
{
3031
hasOverloadsWithDifferentPointerKindsToSameType.Overload(foo, 0);
32+
using (var foo2 = new Foo2())
33+
hasOverloadsWithDifferentPointerKindsToSameType.Overload(foo2, 0);
34+
}
3135
}
3236
using (var overridesNonDirectVirtual = new OverridesNonDirectVirtual())
3337
{

tests/Common/Common.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ Bar::Bar()
108108
{
109109
}
110110

111-
Bar::Bar(Foo foo)
111+
Bar::Bar(const Foo* foo)
112112
{
113113
}
114114

115-
Bar::Bar(const Foo* foo)
115+
Bar::Bar(Foo foo)
116116
{
117117
}
118118

@@ -853,6 +853,14 @@ void HasOverloadsWithDifferentPointerKindsToSameType::overload(Foo& rx, int from
853853
{
854854
}
855855

856+
void HasOverloadsWithDifferentPointerKindsToSameType::overload(const Foo2& rx, int from)
857+
{
858+
}
859+
860+
void HasOverloadsWithDifferentPointerKindsToSameType::overload(Foo2&& rx, int from)
861+
{
862+
}
863+
856864
void HasOverloadsWithDifferentPointerKindsToSameType::dispose()
857865
{
858866
}

tests/Common/Common.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ struct DLL_API Bar
125125
};
126126

127127
Bar();
128-
Bar(Foo foo);
129128
explicit Bar(const Foo* foo);
129+
Bar(Foo foo);
130130
Item RetItem1() const;
131131
int A;
132132
float B;
@@ -1310,6 +1310,8 @@ class DLL_API HasOverloadsWithDifferentPointerKindsToSameType
13101310
void overload(const int& i);
13111311
void overload(const Foo& rx, int from = -1);
13121312
void overload(Foo& rx, int from = -1);
1313+
void overload(const Foo2& rx, int from = -1);
1314+
void overload(Foo2&& rx, int from = -1);
13131315
void dispose();
13141316
};
13151317

0 commit comments

Comments
 (0)