From e0124cd03d9070523e98498bc89786c1505fa9e2 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Thu, 5 Mar 2009 11:40:48 +0000 Subject: [PATCH] Name resolution in new expressions, bug 267168. --- .../core/parser/tests/ast2/AST2CPPTests.java | 16 +++++++++ .../dom/parser/cpp/semantics/LookupData.java | 36 +++++++++++++------ 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index d107834246e..2f1ae56dbbc 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -6927,4 +6927,20 @@ public class AST2CPPTests extends AST2BaseTest { BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); ba.assertNonProblem("f(!p)", 1); } + + // class S { + // S(int); + // }; + // void test() { + // S **temp = new S*[1]; // problem on S + // temp = new S*; // problem on S + // temp = new (S*); // problem on S + // temp = new ::S*[1]; // problem on S + // temp = new ::S*; // problem on S + // temp = new (::S*); // problem on S + // } + public void testNewPointerOfClass_267168() throws Exception { + final String code = getAboveComment(); + parseAndCheckBindings(code, ParserLanguage.CPP); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java index 3b82153587c..44da197ac59 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java @@ -38,6 +38,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; @@ -253,26 +254,39 @@ public class LookupData { IASTNode p1 = astName.getParent(); IASTNode p2 = p1.getParent(); - if (p1 instanceof ICPPASTConstructorChainInitializer) - return true; - if (p1 instanceof ICPPASTNamedTypeSpecifier && p2 instanceof IASTTypeId) { - return p2.getParent() instanceof ICPPASTNewExpression; - } else if (p1 instanceof ICPPASTQualifiedName) { + if (p1 instanceof ICPPASTQualifiedName) { if (((ICPPASTQualifiedName) p1).getLastName() != astName) return false; if (p2 instanceof ICPPASTFunctionDeclarator) { IASTName[] names = ((ICPPASTQualifiedName)p1).getNames(); if (names.length >= 2 && names[names.length - 1] == astName) return CPPVisitor.isConstructor(names[names.length - 2], (IASTDeclarator) p2); - } else if (p2 instanceof ICPPASTNamedTypeSpecifier) { - IASTNode p3 = p2.getParent(); - return p3 instanceof IASTTypeId && p3.getParent() instanceof ICPPASTNewExpression; - } else if (p2 instanceof IASTIdExpression) { - return p2.getParent() instanceof IASTFunctionCallExpression; } - } else if (p1 instanceof IASTFunctionCallExpression || p2 instanceof IASTFunctionCallExpression) { + if (p2 != null) { + p1= p2; + p2= p1.getParent(); + } + } + if (p1 instanceof ICPPASTConstructorChainInitializer) { return true; } + if (p1 instanceof IASTExpression) { + if (p1 instanceof IASTIdExpression) { + p1= p1.getParent(); + } + while (p1 instanceof IASTUnaryExpression && ((IASTUnaryExpression) p1).getOperator() == IASTUnaryExpression.op_bracketedPrimary) { + p1= p1.getParent(); + } + if (p1 instanceof IASTFunctionCallExpression) { + return true; + } + } else if (p1 instanceof ICPPASTNamedTypeSpecifier && p2 instanceof IASTTypeId) { + if (p2.getParent() instanceof ICPPASTNewExpression) { + IASTDeclarator dtor = ((IASTTypeId) p2).getAbstractDeclarator(); + if (dtor.getPointerOperators().length == 0) + return true; + } + } return false; }