1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 354599: Ambiguity resolution to correctly add parameters into scope cache.

This commit is contained in:
Markus Schorn 2011-08-18 11:39:03 +02:00
parent e518891437
commit 623b913281
3 changed files with 39 additions and 15 deletions

View file

@ -9463,4 +9463,21 @@ public class AST2CPPTests extends AST2BaseTest {
public void testTypedefAsClassNameWithFunctionPtrArgument_350345() throws Exception { public void testTypedefAsClassNameWithFunctionPtrArgument_350345() throws Exception {
parseAndCheckBindings(); 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();
}
} }

View file

@ -64,7 +64,16 @@ final class CPPASTAmbiguityResolver extends ASTVisitor {
break; break;
} }
if (node instanceof IASTParameterDeclaration) { 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; break;
} }
if (node instanceof IASTExpression) { if (node instanceof IASTExpression) {

View file

@ -52,7 +52,7 @@ public abstract class CPPASTNameBase extends ASTNode implements IASTName {
public final void incResolutionDepth() { public final void incResolutionDepth() {
if (fBinding == null && ++fResolutionDepth > MAX_RESOLUTION_DEPTH) { 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() { public IBinding resolvePreBinding() {
if (fBinding == null) { if (fBinding == null) {
if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) { if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) {
fBinding= new RecursionResolvingBinding(this); setBinding(new RecursionResolvingBinding(this));
} else { } else {
fBinding= createIntermediateBinding(); setBinding(createIntermediateBinding());
} }
} }
return fBinding; return fBinding;
@ -80,7 +80,7 @@ public abstract class CPPASTNameBase extends ASTNode implements IASTName {
public IBinding resolveBinding() { public IBinding resolveBinding() {
if (fBinding == null) { if (fBinding == null) {
if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) { if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) {
fBinding= new RecursionResolvingBinding(this); setBinding(new RecursionResolvingBinding(this));
} else { } else {
fIsFinal= false; fIsFinal= false;
final IBinding b= createIntermediateBinding(); final IBinding b= createIntermediateBinding();
@ -91,7 +91,7 @@ public abstract class CPPASTNameBase extends ASTNode implements IASTName {
pb.setASTNode(this); pb.setASTNode(this);
} }
} }
fBinding= b; setBinding(b);
} }
} }
if (!fIsFinal) if (!fIsFinal)
@ -106,13 +106,14 @@ public abstract class CPPASTNameBase extends ASTNode implements IASTName {
* @see ICPPTwoPhaseBinding * @see ICPPTwoPhaseBinding
*/ */
public IBinding getPreBinding() { public IBinding getPreBinding() {
final IBinding cand= fBinding;
if (cand == null)
return null;
return fBinding; 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() { public IBinding getBinding() {
final IBinding cand= fBinding; final IBinding cand= fBinding;
if (cand == null) if (cand == null)
@ -128,15 +129,12 @@ public abstract class CPPASTNameBase extends ASTNode implements IASTName {
if (fBinding instanceof ICPPTwoPhaseBinding) { if (fBinding instanceof ICPPTwoPhaseBinding) {
ICPPTwoPhaseBinding intermediateBinding= (ICPPTwoPhaseBinding) fBinding; ICPPTwoPhaseBinding intermediateBinding= (ICPPTwoPhaseBinding) fBinding;
if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) { if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) {
fBinding= new RecursionResolvingBinding(this); setBinding(new RecursionResolvingBinding(this));
} else { } else {
IBinding finalBinding= intermediateBinding.resolveFinalBinding(astName); setBinding(intermediateBinding.resolveFinalBinding(astName));
fBinding= finalBinding;
} }
} }
fIsFinal= true; fIsFinal= true;
fResolutionDepth= 0;
} }
public void setBinding(IBinding binding) { public void setBinding(IBinding binding) {