Browse Source

Prefer non-mapped types when resolving ambiguous overloads

This fixes a missing specialized method when it has a parameter with type a mapped template which is ignored when dependent.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
bug-pass-const-char-star-no-copy
Dimitar Dobrev 6 years ago
parent
commit
c0510730f0
  1. 11
      src/Generator/Passes/CheckAmbiguousFunctions.cs
  2. 2
      tests/CSharp/CSharp.cs
  3. 6
      tests/CSharp/CSharpTemplates.h

11
src/Generator/Passes/CheckAmbiguousFunctions.cs

@ -75,6 +75,9 @@ namespace CppSharp.Passes
var commonParameters = Math.Min(functionParams.Count, overloadParams.Count); var commonParameters = Math.Min(functionParams.Count, overloadParams.Count);
int functionMappedParams = 0;
int overloadMappedParams = 0;
var i = 0; var i = 0;
for (; i < commonParameters; ++i) for (; i < commonParameters; ++i)
{ {
@ -83,6 +86,11 @@ namespace CppSharp.Passes
AST.Type overloadType = overloadParams[i].Type.GetMappedType( AST.Type overloadType = overloadParams[i].Type.GetMappedType(
TypeMaps, Options.GeneratorKind); TypeMaps, Options.GeneratorKind);
if (!funcType.Equals(functionParams[i].Type.Desugar()))
functionMappedParams++;
if (!overloadType.Equals(overloadParams[i].Type.Desugar()))
overloadMappedParams++;
AST.Type funcPointee = funcType.GetFinalPointee() ?? funcType; AST.Type funcPointee = funcType.GetFinalPointee() ?? funcType;
AST.Type overloadPointee = overloadType.GetFinalPointee() ?? overloadType; AST.Type overloadPointee = overloadType.GetFinalPointee() ?? overloadType;
@ -106,7 +114,8 @@ namespace CppSharp.Passes
return false; return false;
} }
if (functionParams.Count > overloadParams.Count) if (functionParams.Count > overloadParams.Count ||
functionMappedParams < overloadMappedParams)
overload.ExplicitlyIgnore(); overload.ExplicitlyIgnore();
else else
function.ExplicitlyIgnore(); function.ExplicitlyIgnore();

2
tests/CSharp/CSharp.cs

@ -149,6 +149,8 @@ namespace CppSharp.Tests
} }
} }
public override bool IsIgnored => Type.IsDependent;
private static Type GetEnumType(Type mappedType) private static Type GetEnumType(Type mappedType)
{ {
var type = mappedType.Desugar(); var type = mappedType.Desugar();

6
tests/CSharp/CSharpTemplates.h

@ -706,17 +706,17 @@ template <typename T>
class HasCtorWithMappedToEnum class HasCtorWithMappedToEnum
{ {
public: public:
HasCtorWithMappedToEnum(QFlags<T> t);
HasCtorWithMappedToEnum(T t); HasCtorWithMappedToEnum(T t);
HasCtorWithMappedToEnum(QFlags<T> t);
}; };
template <typename T> template <typename T>
HasCtorWithMappedToEnum<T>::HasCtorWithMappedToEnum(QFlags<T> t) HasCtorWithMappedToEnum<T>::HasCtorWithMappedToEnum(T t)
{ {
} }
template <typename T> template <typename T>
HasCtorWithMappedToEnum<T>::HasCtorWithMappedToEnum(T t) HasCtorWithMappedToEnum<T>::HasCtorWithMappedToEnum(QFlags<T> t)
{ {
} }

Loading…
Cancel
Save