Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#457] Fix partial specialisation matching for deduced primitive types #458

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6903,6 +6903,37 @@ public void testSfinae_c() throws Exception {
assertTrue(varIp.getType().isSameType(varJp.getType()));
}

// template <typename A, typename B = typename A::t1>
// struct C {
// };
//
// template <typename A>
// struct C<A, decltype(typename A::t1())> {
// int ccc1;
// using t = int;
// };
//
// template <typename A>
// struct C<A, decltype(typename A::t2())> {
// int ccc2;
// };
//
// struct marker {
// using t1 = int;
// using t2 = long;
// };
//
// int b1 = C<marker>().ccc1;
// C<marker>::t b2;
public void testSfinae_d() throws Exception {
BindingAssertionHelper bh = getAssertionHelper();

IVariable varB1 = bh.assertNonProblem("b1");
IVariable varB2 = bh.assertNonProblem("b2");
assertFalse(varB1.getInitialValue() instanceof IProblemBinding);
assertTrue(varB1.getType().isSameType(varB2.getType()));
}

// template<typename T>
// struct is_pod {
// static const bool value = __is_pod(T);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1614,19 +1614,23 @@ public static IType instantiateType(final IType type, InstantiationContext conte
}
}
} else if (type instanceof TypeOfUnknownMember) {
IBinding binding = resolveUnknown(((TypeOfUnknownMember) type).getUnknownMember(), context);
if (binding instanceof IType) {
return (IType) binding;
} else if (binding instanceof IVariable) {
return ((IVariable) binding).getType();
} else if (binding instanceof IFunction) {
return ((IFunction) binding).getType();
BindingOrType bindingType = resolveUnknownBindingOrType(
((TypeOfUnknownMember) type).getUnknownMember(), context);
if (bindingType.getType() != null) {
return bindingType.getType();
} else {
IBinding binding = bindingType.getBinding();
if (binding instanceof IVariable) {
return ((IVariable) binding).getType();
} else if (binding instanceof IFunction) {
return ((IFunction) binding).getType();
}
}
return type;
} else {
IBinding binding = resolveUnknown((ICPPUnknownBinding) type, context);
if (binding instanceof IType)
return (IType) binding;
BindingOrType bindingType = resolveUnknownBindingOrType((ICPPUnknownBinding) type, context);
if (bindingType.getType() != null)
return bindingType.getType();

return type;
}
Expand Down Expand Up @@ -3116,29 +3120,63 @@ public static boolean containsDependentArg(ObjectMap tpMap) {

/**
* Attempts to (partially) resolve an unknown binding with the given arguments.
* Cannot resolved types that are not representable as a binding.
*/
public static IBinding resolveUnknown(ICPPUnknownBinding unknown, InstantiationContext context)
throws DOMException {
BindingOrType bindingType = resolveUnknownBindingOrType(unknown, context);
if (bindingType.getBinding() != null)
return bindingType.getBinding();
return unknown;
}

public static class BindingOrType {
Object bindingOrType;

BindingOrType(IBinding binding) {
bindingOrType = binding;
}

BindingOrType(IType type) {
bindingOrType = type;
}

IType getType() {
if (bindingOrType instanceof IType)
return (IType) bindingOrType;
return null;
}

IBinding getBinding() {
if (bindingOrType instanceof IBinding)
return (IBinding) bindingOrType;
return null;
}
}

/**
* Attempts to (partially) resolve an unknown binding with the given arguments.
*/
public static BindingOrType resolveUnknownBindingOrType(ICPPUnknownBinding unknown, InstantiationContext context)
throws DOMException {
if (unknown instanceof ICPPDeferredClassInstance) {
return resolveDeferredClassInstance((ICPPDeferredClassInstance) unknown, context);
return new BindingOrType(resolveDeferredClassInstance((ICPPDeferredClassInstance) unknown, context));
}
if (unknown instanceof ICPPDeferredVariableInstance) {
return resolveDeferredVariableInstance((ICPPDeferredVariableInstance) unknown, context);
return new BindingOrType(resolveDeferredVariableInstance((ICPPDeferredVariableInstance) unknown, context));
}
if (unknown instanceof ICPPUnknownMember) {
return resolveUnknownMember((ICPPUnknownMember) unknown, context);
return new BindingOrType(resolveUnknownMember((ICPPUnknownMember) unknown, context));
}
if (unknown instanceof ICPPTemplateParameter && unknown instanceof IType) {
IType type = resolveTemplateTypeParameter((ICPPTemplateParameter) unknown, context);
if (type instanceof IBinding)
return (IBinding) type;
return new BindingOrType(type);
}
if (unknown instanceof TypeOfDependentExpression) {
IType type = instantiateType((IType) unknown, context);
if (type instanceof IBinding)
return (IBinding) type;
return new BindingOrType(type);
}
return unknown;
return new BindingOrType(unknown);
}

private static IBinding resolveUnknownMember(ICPPUnknownMember unknown, InstantiationContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1044,11 +1044,13 @@ private boolean fromType(IType p, IType a, boolean allowCVQConversion, boolean v

// Verify that the resolved binding matches the argument type.
InstantiationContext context = InstantiationContext.forDeduction(fDeducedArgs);
IBinding binding = CPPTemplates.resolveUnknown((ICPPUnknownBinding) p, context);
if (binding instanceof ICPPUnknownBinding)
CPPTemplates.BindingOrType bindingType = CPPTemplates
.resolveUnknownBindingOrType((ICPPUnknownBinding) p, context);
if (bindingType.getBinding() instanceof ICPPUnknownBinding)
return true; // An unknown type may match anything.

return binding instanceof IType && ((IType) binding).isSameType(a);
if (bindingType.getType() != null) {
return bindingType.getType().isSameType(a);
}
} else {
return p.isSameType(a);
}
Expand Down
Loading