1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fixed cost calculation for const char& to char& conversion. Bug 248774.

This commit is contained in:
Sergey Prigogin 2008-09-26 21:01:04 +00:00
parent fed63c785d
commit d7dee70d25
2 changed files with 25 additions and 9 deletions

View file

@ -123,7 +123,6 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
public class AST2CPPTests extends AST2BaseTest { public class AST2CPPTests extends AST2BaseTest {
public AST2CPPTests() { public AST2CPPTests() {
} }
@ -6013,4 +6012,18 @@ public class AST2CPPTests extends AST2BaseTest {
public void testScopeOfCatchHandler_Bug209579() throws Exception { public void testScopeOfCatchHandler_Bug209579() throws Exception {
parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP);
} }
// void func(const char& c);
// void func(char& c);
//
// void test(const char& x, char& y) {
// func(x);
// func(y);
// }
public void testOverloadedFunction_248774() throws Exception {
BindingAssertionHelper helper= new BindingAssertionHelper(getAboveComment(), true);
ICPPFunction func1= helper.assertNonProblem("func(x)", 4, ICPPFunction.class);
ICPPFunction func2= helper.assertNonProblem("func(y)", 4, ICPPFunction.class);
assertNotSame(func1, func2);
}
} }

View file

@ -611,6 +611,9 @@ public class Conversions {
firstPointer= false; firstPointer= false;
} }
if (cost.targetHadReference && s instanceof ICPPReferenceType) {
s = ((ICPPReferenceType) s).getType();
}
if (s instanceof IQualifierType ^ t instanceof IQualifierType) { if (s instanceof IQualifierType ^ t instanceof IQualifierType) {
if (t instanceof IQualifierType) { if (t instanceof IQualifierType) {
if (!constInEveryCV2k) { if (!constInEveryCV2k) {
@ -623,11 +626,10 @@ public class Conversions {
} else { } else {
//4.2-2 a string literal can be converted to pointer to char //4.2-2 a string literal can be converted to pointer to char
if (t instanceof IBasicType && ((IBasicType)t).getType() == IBasicType.t_char && if (t instanceof IBasicType && ((IBasicType)t).getType() == IBasicType.t_char &&
s instanceof IQualifierType) s instanceof IQualifierType) {
{ IType qt = ((IQualifierType) s).getType();
IType qt = ((IQualifierType)s).getType();
if (qt instanceof IBasicType) { if (qt instanceof IBasicType) {
IASTExpression val = ((IBasicType)qt).getValue(); IASTExpression val = ((IBasicType) qt).getValue();
canConvert = (val != null && canConvert = (val != null &&
val instanceof IASTLiteralExpression && val instanceof IASTLiteralExpression &&
((IASTLiteralExpression)val).getKind() == IASTLiteralExpression.lk_string_literal); ((IASTLiteralExpression)val).getKind() == IASTLiteralExpression.lk_string_literal);
@ -641,7 +643,8 @@ public class Conversions {
} }
} }
} else if (s instanceof IQualifierType && t instanceof IQualifierType) { } else if (s instanceof IQualifierType && t instanceof IQualifierType) {
IQualifierType qs = (IQualifierType) s, qt = (IQualifierType) t; IQualifierType qs = (IQualifierType) s;
IQualifierType qt = (IQualifierType) t;
if (qs.isConst() == qt.isConst() && qs.isVolatile() == qt.isVolatile()) { if (qs.isConst() == qt.isConst() && qs.isVolatile() == qt.isVolatile()) {
requiredConversion = Cost.IDENTITY_RANK; requiredConversion = Cost.IDENTITY_RANK;
} else if ((qs.isConst() && !qt.isConst()) || (qs.isVolatile() && !qt.isVolatile()) || !constInEveryCV2k) { } else if ((qs.isConst() && !qt.isConst()) || (qs.isVolatile() && !qt.isVolatile()) || !constInEveryCV2k) {
@ -654,18 +657,18 @@ public class Conversions {
canConvert = true; canConvert = true;
requiredConversion = Cost.CONVERSION_RANK; requiredConversion = Cost.CONVERSION_RANK;
int i = 1; int i = 1;
for (IType type = s; canConvert == true && i == 1; type = t, i++) { for (IType type = s; canConvert && i == 1; type = t, i++) {
while (type instanceof ITypeContainer) { while (type instanceof ITypeContainer) {
if (type instanceof IQualifierType) { if (type instanceof IQualifierType) {
canConvert = false; canConvert = false;
} else if (type instanceof IPointerType) { } else if (type instanceof IPointerType) {
canConvert = !((IPointerType)type).isConst() && !((IPointerType)type).isVolatile(); canConvert = !((IPointerType) type).isConst() && !((IPointerType) type).isVolatile();
} }
if (!canConvert) { if (!canConvert) {
requiredConversion = Cost.NO_MATCH_RANK; requiredConversion = Cost.NO_MATCH_RANK;
break; break;
} }
type = ((ITypeContainer)type).getType(); type = ((ITypeContainer) type).getType();
} }
} }
} }