Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2017-11-07 16:32:29 -0500
committerNathan Ridge2017-11-14 19:47:39 -0500
commit1bf0dff19f90158633ea4f84a3b0851bb801160b (patch)
treef9afc836dbbf88601e5816118b123db7dd269cea
parentc9c292982dba022f3e481a9630c398e81db87d78 (diff)
downloadorg.eclipse.cdt-1bf0dff19f90158633ea4f84a3b0851bb801160b.tar.gz
org.eclipse.cdt-1bf0dff19f90158633ea4f84a3b0851bb801160b.tar.xz
org.eclipse.cdt-1bf0dff19f90158633ea4f84a3b0851bb801160b.zip
Bug 526857 - Diagnose member access into pointer type in C code
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java12
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java8
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java2
3 files changed, 21 insertions, 1 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
index 8a9675c606..41f594e052 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
@@ -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");
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
index b582c2e4bb..30e97d86fa 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
@@ -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();
}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java
index ba2995fbd0..57411a3db2 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java
@@ -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"

Back to the top