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:
parent
fed63c785d
commit
d7dee70d25
2 changed files with 25 additions and 9 deletions
|
@ -123,7 +123,6 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
|
||||
public class AST2CPPTests extends AST2BaseTest {
|
||||
|
||||
|
||||
public AST2CPPTests() {
|
||||
}
|
||||
|
||||
|
@ -6013,4 +6012,18 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
public void testScopeOfCatchHandler_Bug209579() throws Exception {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -611,6 +611,9 @@ public class Conversions {
|
|||
firstPointer= false;
|
||||
}
|
||||
|
||||
if (cost.targetHadReference && s instanceof ICPPReferenceType) {
|
||||
s = ((ICPPReferenceType) s).getType();
|
||||
}
|
||||
if (s instanceof IQualifierType ^ t instanceof IQualifierType) {
|
||||
if (t instanceof IQualifierType) {
|
||||
if (!constInEveryCV2k) {
|
||||
|
@ -623,11 +626,10 @@ public class Conversions {
|
|||
} else {
|
||||
//4.2-2 a string literal can be converted to pointer to char
|
||||
if (t instanceof IBasicType && ((IBasicType)t).getType() == IBasicType.t_char &&
|
||||
s instanceof IQualifierType)
|
||||
{
|
||||
IType qt = ((IQualifierType)s).getType();
|
||||
s instanceof IQualifierType) {
|
||||
IType qt = ((IQualifierType) s).getType();
|
||||
if (qt instanceof IBasicType) {
|
||||
IASTExpression val = ((IBasicType)qt).getValue();
|
||||
IASTExpression val = ((IBasicType) qt).getValue();
|
||||
canConvert = (val != null &&
|
||||
val instanceof IASTLiteralExpression &&
|
||||
((IASTLiteralExpression)val).getKind() == IASTLiteralExpression.lk_string_literal);
|
||||
|
@ -641,7 +643,8 @@ public class Conversions {
|
|||
}
|
||||
}
|
||||
} 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()) {
|
||||
requiredConversion = Cost.IDENTITY_RANK;
|
||||
} else if ((qs.isConst() && !qt.isConst()) || (qs.isVolatile() && !qt.isVolatile()) || !constInEveryCV2k) {
|
||||
|
@ -654,18 +657,18 @@ public class Conversions {
|
|||
canConvert = true;
|
||||
requiredConversion = Cost.CONVERSION_RANK;
|
||||
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) {
|
||||
if (type instanceof IQualifierType) {
|
||||
canConvert = false;
|
||||
} else if (type instanceof IPointerType) {
|
||||
canConvert = !((IPointerType)type).isConst() && !((IPointerType)type).isVolatile();
|
||||
canConvert = !((IPointerType) type).isConst() && !((IPointerType) type).isVolatile();
|
||||
}
|
||||
if (!canConvert) {
|
||||
requiredConversion = Cost.NO_MATCH_RANK;
|
||||
break;
|
||||
}
|
||||
type = ((ITypeContainer)type).getType();
|
||||
type = ((ITypeContainer) type).getType();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue