1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-09 19:43:27 +02:00

Bug 263159.

This commit is contained in:
Sergey Prigogin 2009-02-04 02:15:03 +00:00
parent 897c5adf97
commit 29a0119ac0
3 changed files with 42 additions and 27 deletions

View file

@ -4945,17 +4945,17 @@ public class AST2CPPTests extends AST2BaseTest {
assertSame( b, col.getName(10).resolveBinding() ); assertSame( b, col.getName(10).resolveBinding() );
} }
// void free( void * ); // void free(void*);
// void f( char **p ){ // void f(char** p) {
// free( p ); // free(p);
// } // }
public void testBug100415() throws Exception { public void testBug100415() throws Exception {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true ); IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true);
CPPNameCollector col = new CPPNameCollector(); CPPNameCollector col = new CPPNameCollector();
tu.accept( col ); tu.accept(col);
IFunction free = (IFunction) col.getName(0).resolveBinding(); IFunction free = (IFunction) col.getName(0).resolveBinding();
assertSame( free, col.getName(4).resolveBinding() ); assertSame(free, col.getName(4).resolveBinding());
} }
// class X; // class X;
@ -6641,11 +6641,17 @@ public class AST2CPPTests extends AST2BaseTest {
// void f(int x); // void f(int x);
// //
// void test(int* p) { // void test(int* p, const int* q, int r[], const int s[]) {
// f(p); // f(p);
// f(q);
// f(r);
// f(s);
// } // }
public void _testPointerToNonPointerConversion_263159() throws Exception { public void testPointerToNonPointerConversion_263159() throws Exception {
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
ba.assertProblem("f(p)", 1); ba.assertProblem("f(p)", 1);
ba.assertProblem("f(q)", 1);
ba.assertProblem("f(r)", 1);
ba.assertProblem("f(s)", 1);
} }
} }

View file

@ -3047,7 +3047,7 @@ public class AST2TemplateTests extends AST2BaseTest {
// //
// class B { // class B {
// public: // public:
// void foo(const A& b); // void foo(const A* b);
// }; // };
// //
// template<typename T> // template<typename T>
@ -3135,7 +3135,7 @@ public class AST2TemplateTests extends AST2BaseTest {
// template <typename S> X(S s); // template <typename S> X(S s);
// }; // };
// //
// void test(X a); // void test(X* a);
// void bla(int g) { // void bla(int g) {
// test(new X(g)); // test(new X(g));
// } // }

View file

@ -565,6 +565,8 @@ public class Conversions {
IType t = cost.target; IType t = cost.target;
boolean constInEveryCV2k = true; boolean constInEveryCV2k = true;
boolean firstPointer= true; boolean firstPointer= true;
boolean bothArePointers = false;
boolean pointerNonPointerMismatch = false;
while (true) { while (true) {
s= getUltimateTypeViaTypedefs(s); s= getUltimateTypeViaTypedefs(s);
t= getUltimateTypeViaTypedefs(t); t= getUltimateTypeViaTypedefs(t);
@ -572,8 +574,9 @@ public class Conversions {
final boolean targetIsPointer= t instanceof IPointerType; final boolean targetIsPointer= t instanceof IPointerType;
if (!targetIsPointer) { if (!targetIsPointer) {
if (!sourceIsPointer) if (!sourceIsPointer && !(s instanceof IArrayType)) {
break; break;
}
if (t instanceof ICPPBasicType) { if (t instanceof ICPPBasicType) {
if (((ICPPBasicType) t).getType() == ICPPBasicType.t_bool) { if (((ICPPBasicType) t).getType() == ICPPBasicType.t_bool) {
canConvert= true; canConvert= true;
@ -581,17 +584,26 @@ public class Conversions {
break; break;
} }
} }
if (!bothArePointers) {
pointerNonPointerMismatch = true;
}
canConvert = false; canConvert = false;
break; break;
} else if (!sourceIsPointer) { } else if (!sourceIsPointer) {
canConvert = false; if (s instanceof IArrayType) {
break; // 4.2 Array-To-Pointer conversion
s = new CPPPointerType(((IArrayType) s).getType());
} else {
canConvert = false;
break;
}
} else if (s instanceof ICPPPointerToMemberType ^ t instanceof ICPPPointerToMemberType) { } else if (s instanceof ICPPPointerToMemberType ^ t instanceof ICPPPointerToMemberType) {
canConvert = false; canConvert = false;
break; break;
} }
// Both are pointers // Both are pointers
bothArePointers = true;
IPointerType op1= (IPointerType) s; IPointerType op1= (IPointerType) s;
IPointerType op2= (IPointerType) t; IPointerType op2= (IPointerType) t;
@ -656,23 +668,20 @@ public class Conversions {
} else { } else {
requiredConversion = Cost.CONVERSION_RANK; requiredConversion = Cost.CONVERSION_RANK;
} }
} else if (constInEveryCV2k && !canConvert) { } else if (!pointerNonPointerMismatch && constInEveryCV2k && !canConvert) {
canConvert = true; canConvert = true;
requiredConversion = Cost.CONVERSION_RANK; requiredConversion = Cost.CONVERSION_RANK;
int i = 1; while (s instanceof ITypeContainer) {
for (IType type = s; canConvert && i == 1; type = t, i++) { if (s instanceof IQualifierType) {
while (type instanceof ITypeContainer) { canConvert = false;
if (type instanceof IQualifierType) { } else if (s instanceof IPointerType) {
canConvert = false; canConvert = !((IPointerType) s).isConst() && !((IPointerType) s).isVolatile();
} else if (type instanceof IPointerType) {
canConvert = !((IPointerType) type).isConst() && !((IPointerType) type).isVolatile();
}
if (!canConvert) {
requiredConversion = Cost.NO_MATCH_RANK;
break;
}
type = ((ITypeContainer) type).getType();
} }
if (!canConvert) {
requiredConversion = Cost.NO_MATCH_RANK;
break;
}
s = ((ITypeContainer) s).getType();
} }
} }