1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-09 11:33:20 +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() );
}
// void free( void * );
// void f( char **p ){
// free( p );
// void free(void*);
// void f(char** p) {
// free(p);
// }
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();
tu.accept( col );
tu.accept(col);
IFunction free = (IFunction) col.getName(0).resolveBinding();
assertSame( free, col.getName(4).resolveBinding() );
assertSame(free, col.getName(4).resolveBinding());
}
// class X;
@ -6641,11 +6641,17 @@ public class AST2CPPTests extends AST2BaseTest {
// void f(int x);
//
// void test(int* p) {
// void test(int* p, const int* q, int r[], const int s[]) {
// 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);
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 {
// public:
// void foo(const A& b);
// void foo(const A* b);
// };
//
// template<typename T>
@ -3135,7 +3135,7 @@ public class AST2TemplateTests extends AST2BaseTest {
// template <typename S> X(S s);
// };
//
// void test(X a);
// void test(X* a);
// void bla(int g) {
// test(new X(g));
// }

View file

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