Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2011-08-18 09:39:03 +0000
committerMarkus Schorn2011-08-18 09:43:33 +0000
commit623b9132819c9dbd49484104ef5c78d409a48ec6 (patch)
treeb29c3dcfb483177ebe396ad8dc19af566074b518
parente51889143728a4d3b80cee368a6784a182584024 (diff)
downloadorg.eclipse.cdt-623b9132819c9dbd49484104ef5c78d409a48ec6.tar.gz
org.eclipse.cdt-623b9132819c9dbd49484104ef5c78d409a48ec6.tar.xz
org.eclipse.cdt-623b9132819c9dbd49484104ef5c78d409a48ec6.zip
Bug 354599: Ambiguity resolution to correctly add parameters into scope cache.
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java17
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java11
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNameBase.java26
3 files changed, 39 insertions, 15 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 cca271c32ad..6b0d18b3fc3 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
@@ -9463,4 +9463,21 @@ public class AST2CPPTests extends AST2BaseTest {
public void testTypedefAsClassNameWithFunctionPtrArgument_350345() throws Exception {
parseAndCheckBindings();
}
+
+ // int func1(int input) {
+ // return input;
+ // }
+ // void dut() {
+ // int const_zero;
+ // int lll = (func1(func1(const_zero))) + func1(const_zero);
+ // int kkk = (func1(func1(const_zero))) + func1(const_zero);
+ // }
+ //
+ // void f3(int (x), int y=x);
+ // void f2(int (x), int y=x) {
+ // x= 1;
+ // }
+ public void testAmbiguityResolution_Bug354599() throws Exception {
+ parseAndCheckBindings();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java
index 4ab0acfe80b..4fb6e5ec736 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguityResolver.java
@@ -64,7 +64,16 @@ final class CPPASTAmbiguityResolver extends ASTVisitor {
break;
}
if (node instanceof IASTParameterDeclaration) {
- repopulateScope((IASTParameterDeclaration) node);
+ // If the parameter declaration belongs to a function declaration or
+ // function definition we need to update the scope.
+ IASTNode parent= node.getParent();
+ if (parent instanceof IASTDeclarator) {
+ IASTDeclarator dtor= (IASTDeclarator) parent;
+ if (dtor == ASTQueries.findTypeRelevantDeclarator(dtor) &&
+ ASTQueries.findOutermostDeclarator(dtor).getParent() instanceof IASTDeclaration) {
+ repopulateScope((IASTParameterDeclaration) node);
+ }
+ }
break;
}
if (node instanceof IASTExpression) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNameBase.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNameBase.java
index b5a518bd3d9..30c6359b9ed 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNameBase.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNameBase.java
@@ -52,7 +52,7 @@ public abstract class CPPASTNameBase extends ASTNode implements IASTName {
public final void incResolutionDepth() {
if (fBinding == null && ++fResolutionDepth > MAX_RESOLUTION_DEPTH) {
- fBinding = new RecursionResolvingBinding(this);
+ setBinding(new RecursionResolvingBinding(this));
}
}
@@ -69,9 +69,9 @@ public abstract class CPPASTNameBase extends ASTNode implements IASTName {
public IBinding resolvePreBinding() {
if (fBinding == null) {
if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) {
- fBinding= new RecursionResolvingBinding(this);
+ setBinding(new RecursionResolvingBinding(this));
} else {
- fBinding= createIntermediateBinding();
+ setBinding(createIntermediateBinding());
}
}
return fBinding;
@@ -80,7 +80,7 @@ public abstract class CPPASTNameBase extends ASTNode implements IASTName {
public IBinding resolveBinding() {
if (fBinding == null) {
if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) {
- fBinding= new RecursionResolvingBinding(this);
+ setBinding(new RecursionResolvingBinding(this));
} else {
fIsFinal= false;
final IBinding b= createIntermediateBinding();
@@ -91,7 +91,7 @@ public abstract class CPPASTNameBase extends ASTNode implements IASTName {
pb.setASTNode(this);
}
}
- fBinding= b;
+ setBinding(b);
}
}
if (!fIsFinal)
@@ -106,13 +106,14 @@ public abstract class CPPASTNameBase extends ASTNode implements IASTName {
* @see ICPPTwoPhaseBinding
*/
public IBinding getPreBinding() {
- final IBinding cand= fBinding;
- if (cand == null)
- return null;
-
return fBinding;
}
+ /**
+ * If this name has not yet been resolved at all, <code>null</code> will be returned.
+ * Otherwise the final binding for this name is returned.
+ * @see ICPPTwoPhaseBinding
+ */
public IBinding getBinding() {
final IBinding cand= fBinding;
if (cand == null)
@@ -128,15 +129,12 @@ public abstract class CPPASTNameBase extends ASTNode implements IASTName {
if (fBinding instanceof ICPPTwoPhaseBinding) {
ICPPTwoPhaseBinding intermediateBinding= (ICPPTwoPhaseBinding) fBinding;
if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) {
- fBinding= new RecursionResolvingBinding(this);
+ setBinding(new RecursionResolvingBinding(this));
} else {
- IBinding finalBinding= intermediateBinding.resolveFinalBinding(astName);
- fBinding= finalBinding;
+ setBinding(intermediateBinding.resolveFinalBinding(astName));
}
}
-
fIsFinal= true;
- fResolutionDepth= 0;
}
public void setBinding(IBinding binding) {

Back to the top