1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Bug 506728 - Ref-qualified conversion operator

Change-Id: Ic5e1650bdd1235fd953ab79e44f801c0b52badf3
This commit is contained in:
Nathan Ridge 2016-10-29 00:45:32 -04:00
parent 4fa9706ea8
commit b6bda6636c
2 changed files with 22 additions and 2 deletions

View file

@ -1749,6 +1749,21 @@ public class AST2CPPTests extends AST2TestBase {
assertSame(oper, conv); assertSame(oper, conv);
} }
// struct S {
// operator int() &;
// operator int() &&;
// };
//
// void waldo(int);
//
// int main() {
// S s;
// waldo(s); // ERROR
// }
public void testOverloadedRefQualifiedConversionOperators_506728() throws Exception {
parseAndCheckBindings();
}
// namespace A { int x; } // namespace A { int x; }
// namespace B = A; // namespace B = A;
// int f(){ B::x; } // int f(){ B::x; }

View file

@ -856,7 +856,8 @@ public class Conversions {
if (isExplicitConversion /** && !direct **/) if (isExplicitConversion /** && !direct **/)
continue; continue;
final IType returnType = op.getType().getReturnType(); ICPPFunctionType functionType = op.getType();
final IType returnType = functionType.getReturnType();
IType uqReturnType= getNestedType(returnType, TDEF | ALLCVQ); IType uqReturnType= getNestedType(returnType, TDEF | ALLCVQ);
Cost c2= checkImplicitConversionSequence(target, uqReturnType, valueCategoryFromReturnType(uqReturnType), UDCMode.FORBIDDEN, Context.ORDINARY, point); Cost c2= checkImplicitConversionSequence(target, uqReturnType, valueCategoryFromReturnType(uqReturnType), UDCMode.FORBIDDEN, Context.ORDINARY, point);
if (c2.converts()) { if (c2.converts()) {
@ -866,7 +867,11 @@ public class Conversions {
final Cost udcCost = isReferenceCompatible(getNestedType(implicitType, TDEF | REF), source, true, point); final Cost udcCost = isReferenceCompatible(getNestedType(implicitType, TDEF | REF), source, true, point);
if (udcCost != null) { if (udcCost != null) {
// Make sure top-level cv-qualifiers are compared // Make sure top-level cv-qualifiers are compared
if (functionType.hasRefQualifier() && functionType.isRValueReference()) {
udcCost.setReferenceBinding(ReferenceBinding.RVALUE_REF_BINDS_RVALUE);
} else {
udcCost.setReferenceBinding(ReferenceBinding.LVALUE_REF); udcCost.setReferenceBinding(ReferenceBinding.LVALUE_REF);
}
FunctionCost c1= new FunctionCost(op, udcCost, point); FunctionCost c1= new FunctionCost(op, udcCost, point);
int cmp= c1.compareTo(null, cost1); int cmp= c1.compareTo(null, cost1);
if (cmp <= 0) { if (cmp <= 0) {