1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 01:36:01 +02:00

Bug 526857 - Diagnose member access into pointer type in C code

Change-Id: Ib6fc6be443d59facacde3c290e0f974e5cbe6f1b
This commit is contained in:
Nathan Ridge 2017-11-07 16:32:29 -05:00
parent c9c292982d
commit 1bf0dff19f
3 changed files with 21 additions and 1 deletions

View file

@ -7704,4 +7704,16 @@ public class AST2Tests extends AST2TestBase {
IASTConditionalExpression expr = helper.assertNode("cond ? arr1 : arr2");
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");
}
}

View file

@ -604,8 +604,16 @@ public class CVisitor extends ASTQueries {
if (fieldOwner == null)
return null;
boolean isPointerDeref = fieldReference.isPointerDereference();
IType type = fieldOwner.getExpressionType();
while (type != null && type instanceof ITypeContainer) {
if (type instanceof IPointerType) {
if (isPointerDeref) {
isPointerDeref = false;
} else {
return null;
}
}
type = ((ITypeContainer) type).getType();
}

View file

@ -591,7 +591,7 @@ public class CompletionTests_PlainC extends AbstractContentAssistTest {
//#define STRUCT_C1
///*include*/
//void gfunc() {gfC1().m/*cursor*/
//void gfunc() {gfC1()->m/*cursor*/
public void testGlobalFunction() throws Exception {
final String[] expected= {
"m123", "m12", "m13"