mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 12:03:16 +02:00
Bug 263159.
This commit is contained in:
parent
897c5adf97
commit
29a0119ac0
3 changed files with 42 additions and 27 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
||||||
// }
|
// }
|
||||||
|
|
|
@ -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) {
|
||||||
|
if (s instanceof IArrayType) {
|
||||||
|
// 4.2 Array-To-Pointer conversion
|
||||||
|
s = new CPPPointerType(((IArrayType) s).getType());
|
||||||
|
} else {
|
||||||
canConvert = false;
|
canConvert = false;
|
||||||
break;
|
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) {
|
|
||||||
if (type instanceof IQualifierType) {
|
|
||||||
canConvert = false;
|
canConvert = false;
|
||||||
} else if (type instanceof IPointerType) {
|
} else if (s instanceof IPointerType) {
|
||||||
canConvert = !((IPointerType) type).isConst() && !((IPointerType) type).isVolatile();
|
canConvert = !((IPointerType) s).isConst() && !((IPointerType) s).isVolatile();
|
||||||
}
|
}
|
||||||
if (!canConvert) {
|
if (!canConvert) {
|
||||||
requiredConversion = Cost.NO_MATCH_RANK;
|
requiredConversion = Cost.NO_MATCH_RANK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
type = ((ITypeContainer) type).getType();
|
s = ((ITypeContainer) s).getType();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue