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

Fix qualification ranking problem

This commit is contained in:
Andrew Niefer 2005-06-08 22:02:49 +00:00
parent f875db0ab0
commit 2e56e1ed70
2 changed files with 34 additions and 3 deletions

View file

@ -4658,4 +4658,28 @@ public class AST2CPPTests extends AST2BaseTest {
IParameter p = (IParameter) col.getName(2).resolveBinding(); IParameter p = (IParameter) col.getName(2).resolveBinding();
assertNotNull( p ); assertNotNull( p );
} }
public void testRankingQualificationConversions() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("void f( const int ); \n");
buffer.append("void f( int ); \n");
buffer.append("void g() { f(1); } \n");
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
assertSame( col.getName(2).resolveBinding(), col.getName(5).resolveBinding() );
buffer = new StringBuffer();
buffer.append("void f( const volatile int ); \n");
buffer.append("void f( const int ); \n");
buffer.append("void g() { f(1); } \n");
tu = parse( buffer.toString(), ParserLanguage.CPP );
col = new CPPNameCollector();
tu.accept(col);
assertSame( col.getName(2).resolveBinding(), col.getName(5).resolveBinding() );
}
} }

View file

@ -2618,6 +2618,7 @@ public class CPPSemantics {
static private void qualificationConversion( Cost cost ) throws DOMException{ static private void qualificationConversion( Cost cost ) throws DOMException{
boolean canConvert = true; boolean canConvert = true;
int conversionRequired = 1; //1 means it will work without a conversion, 2 means conversion was needed
IPointerType op1, op2; IPointerType op1, op2;
IType s = cost.source, t = cost.target; IType s = cost.source, t = cost.target;
@ -2671,9 +2672,10 @@ public class CPPSemantics {
} }
if( s instanceof IQualifierType ^ t instanceof IQualifierType ){ if( s instanceof IQualifierType ^ t instanceof IQualifierType ){
if( t instanceof IQualifierType ) if( t instanceof IQualifierType ){
canConvert = true; canConvert = true;
else { conversionRequired = 2;
} 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 )
@ -2695,8 +2697,13 @@ public class CPPSemantics {
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() )
canConvert = false; canConvert = false;
else if( qs.isConst() == qt.isConst() && qs.isVolatile() == qt.isVolatile() )
conversionRequired = 1;
else
conversionRequired = 2;
} else if( constInEveryCV2k && !canConvert ){ } else if( constInEveryCV2k && !canConvert ){
canConvert = true; canConvert = true;
conversionRequired = 2;
int i = 1; int i = 1;
for( IType type = s; canConvert == true && i == 1; type = t, i++ ){ for( IType type = s; canConvert == true && i == 1; type = t, i++ ){
while( type instanceof ITypeContainer ){ while( type instanceof ITypeContainer ){
@ -2713,7 +2720,7 @@ public class CPPSemantics {
} }
if( canConvert == true ){ if( canConvert == true ){
cost.qualification = 1; cost.qualification = conversionRequired;
cost.rank = Cost.LVALUE_OR_QUALIFICATION_RANK; cost.rank = Cost.LVALUE_OR_QUALIFICATION_RANK;
} else { } else {
cost.qualification = 0; cost.qualification = 0;