mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix cv-conversion, bug 213029.
This commit is contained in:
parent
ff426e5841
commit
0408d6e901
2 changed files with 44 additions and 6 deletions
|
@ -4168,4 +4168,31 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
StringBuffer buffer = getContents(1)[0];
|
StringBuffer buffer = getContents(1)[0];
|
||||||
parseAndCheckBindings(buffer.toString(), ParserLanguage.CPP);
|
parseAndCheckBindings(buffer.toString(), ParserLanguage.CPP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// int* i= 0;
|
||||||
|
// void f1(const int**);
|
||||||
|
// void f2(int *const*);
|
||||||
|
// void f3(const int *const*);
|
||||||
|
//
|
||||||
|
// void test() {
|
||||||
|
// f1(&i); // forbidden
|
||||||
|
// f2(&i); // ok
|
||||||
|
// f3(&i); // ok
|
||||||
|
// }
|
||||||
|
public void testBug213029_cvConversion() throws Exception {
|
||||||
|
StringBuffer buffer = getContents(1)[0];
|
||||||
|
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP, false );
|
||||||
|
CNameCollector col = new CNameCollector();
|
||||||
|
tu.accept(col);
|
||||||
|
Iterator i = col.nameList.iterator();
|
||||||
|
while (i.hasNext()) {
|
||||||
|
IASTName n = (IASTName) i.next();
|
||||||
|
if (n.isReference() && "f1".equals(n.toString())) {
|
||||||
|
assertTrue(n.resolveBinding() instanceof IProblemBinding);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assertFalse(n.resolveBinding() instanceof IProblemBinding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -3009,6 +3009,7 @@ public class CPPSemantics {
|
||||||
|
|
||||||
IType s = cost.source, t = cost.target;
|
IType s = cost.source, t = cost.target;
|
||||||
boolean constInEveryCV2k = true;
|
boolean constInEveryCV2k = true;
|
||||||
|
boolean firstPointer= true;
|
||||||
while( true ){
|
while( true ){
|
||||||
s= getUltimateTypeViaTypedefs(s);
|
s= getUltimateTypeViaTypedefs(s);
|
||||||
t= getUltimateTypeViaTypedefs(t);
|
t= getUltimateTypeViaTypedefs(t);
|
||||||
|
@ -3039,15 +3040,22 @@ public class CPPSemantics {
|
||||||
requiredConversion = Cost.NO_MATCH_RANK;
|
requiredConversion = Cost.NO_MATCH_RANK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
constInEveryCV2k &= op2.isConst();
|
constInEveryCV2k &= (firstPointer || op2.isConst());
|
||||||
s = op1.getType();
|
s = op1.getType();
|
||||||
t = op2.getType();
|
t = op2.getType();
|
||||||
|
firstPointer= false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( s instanceof IQualifierType ^ t instanceof IQualifierType ){
|
if( s instanceof IQualifierType ^ t instanceof IQualifierType ){
|
||||||
if( t instanceof IQualifierType ){
|
if( t instanceof IQualifierType ){
|
||||||
canConvert = true;
|
if (!constInEveryCV2k) {
|
||||||
requiredConversion = Cost.CONVERSION_RANK;
|
canConvert= false;
|
||||||
|
requiredConversion= Cost.NO_MATCH_RANK;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
canConvert = true;
|
||||||
|
requiredConversion = Cost.CONVERSION_RANK;
|
||||||
|
}
|
||||||
} 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 &&
|
||||||
|
@ -3070,10 +3078,13 @@ public class CPPSemantics {
|
||||||
}
|
}
|
||||||
} 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, qt = (IQualifierType) t;
|
||||||
if( qs.isConst() && !qt.isConst() || qs.isVolatile() && !qt.isVolatile() )
|
if( qs.isConst() == qt.isConst() && qs.isVolatile() == qt.isVolatile() ) {
|
||||||
requiredConversion = Cost.NO_MATCH_RANK;
|
|
||||||
else 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 ) {
|
||||||
|
requiredConversion = Cost.NO_MATCH_RANK;
|
||||||
|
canConvert= false;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
requiredConversion = Cost.CONVERSION_RANK;
|
requiredConversion = Cost.CONVERSION_RANK;
|
||||||
} else if( constInEveryCV2k && !canConvert ){
|
} else if( constInEveryCV2k && !canConvert ){
|
||||||
|
|
Loading…
Add table
Reference in a new issue