mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Bug 526857 - Diagnose member access into pointer type in C code
Change-Id: Ib6fc6be443d59facacde3c290e0f974e5cbe6f1b
This commit is contained in:
parent
c9c292982d
commit
1bf0dff19f
3 changed files with 21 additions and 1 deletions
|
@ -7704,4 +7704,16 @@ public class AST2Tests extends AST2TestBase {
|
||||||
IASTConditionalExpression expr = helper.assertNode("cond ? arr1 : arr2");
|
IASTConditionalExpression expr = helper.assertNode("cond ? arr1 : arr2");
|
||||||
assertSameType(expr.getExpressionType(), CommonCTypes.pointerToInt);
|
assertSameType(expr.getExpressionType(), CommonCTypes.pointerToInt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// struct S {
|
||||||
|
// int waldo;
|
||||||
|
// };
|
||||||
|
// int main() {
|
||||||
|
// struct S* s;
|
||||||
|
// s.waldo;
|
||||||
|
// }
|
||||||
|
public void testMemberAccessOnPointerType_526857() throws Exception {
|
||||||
|
BindingAssertionHelper helper = getAssertionHelper(C);
|
||||||
|
helper.assertProblem("s.waldo", "waldo");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -604,8 +604,16 @@ public class CVisitor extends ASTQueries {
|
||||||
if (fieldOwner == null)
|
if (fieldOwner == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
boolean isPointerDeref = fieldReference.isPointerDereference();
|
||||||
IType type = fieldOwner.getExpressionType();
|
IType type = fieldOwner.getExpressionType();
|
||||||
while (type != null && type instanceof ITypeContainer) {
|
while (type != null && type instanceof ITypeContainer) {
|
||||||
|
if (type instanceof IPointerType) {
|
||||||
|
if (isPointerDeref) {
|
||||||
|
isPointerDeref = false;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
type = ((ITypeContainer) type).getType();
|
type = ((ITypeContainer) type).getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -591,7 +591,7 @@ public class CompletionTests_PlainC extends AbstractContentAssistTest {
|
||||||
|
|
||||||
//#define STRUCT_C1
|
//#define STRUCT_C1
|
||||||
///*include*/
|
///*include*/
|
||||||
//void gfunc() {gfC1().m/*cursor*/
|
//void gfunc() {gfC1()->m/*cursor*/
|
||||||
public void testGlobalFunction() throws Exception {
|
public void testGlobalFunction() throws Exception {
|
||||||
final String[] expected= {
|
final String[] expected= {
|
||||||
"m123", "m12", "m13"
|
"m123", "m12", "m13"
|
||||||
|
|
Loading…
Add table
Reference in a new issue