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

Bug 462348 - Perform ambiguity resolution on a method body sooner than

at the end of the class definition when necessary

Change-Id: Ia5b17cfcd57f3b1d55281987b48582f084a2c11f
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
Nathan Ridge 2015-03-20 02:58:43 -04:00 committed by Gerrit Code Review @ Eclipse.org
parent c652e20d9b
commit 198b722894
6 changed files with 62 additions and 1 deletions

View file

@ -8762,4 +8762,16 @@ public class AST2TemplateTests extends AST2TestBase {
public void testClassSpecializationInEnumerator_457511() throws Exception {
parseAndCheckBindings();
}
// template <typename> struct TypeTemplate {};
// template <int> struct Size_tTemplate {};
//
// template <typename... ParameterPack> struct Test {
// static constexpr int packSize() { return sizeof...(ParameterPack); }
//
// using type = TypeTemplate<Size_tTemplate<packSize()>>;
// };
public void testAmbiguityResolutionOrder_462348() throws Exception {
parseAndCheckBindings();
}
}

View file

@ -394,4 +394,12 @@ public abstract class ASTNode implements IASTNode {
}
return node;
}
/**
* If ambiguity resolution is in progress, and procesing of this node has been deferred,
* process it now. Has no effect if ambiguity resolution is not in progress.
*/
public void resolvePendingAmbiguities() {
((ASTTranslationUnit) getTranslationUnit()).resolvePendingAmbiguities(this);
}
}

View file

@ -522,4 +522,10 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
assertNotFrozen();
fNodesOmitted = hasNodesOmitted;
}
/**
* If ambiguity resolution is in progress, and processing of 'node' has been deferred,
* process it now. Has no effect if ambiguity resolution is not in progress.
*/
public void resolvePendingAmbiguities(IASTNode node) {}
}

View file

@ -218,4 +218,26 @@ final class CPPASTAmbiguityResolver extends ASTVisitor {
CPPSemantics.populateCache((ICPPASTInternalScope) scope, declaration);
}
}
/**
* If 'node' has been deferred for later processing, process it now.
*/
public void resolvePendingAmbiguities(IASTNode node) {
if (!fDeferredNodes.isEmpty()) {
Deque<IASTNode> deferred = fDeferredNodes.getLast();
for (IASTNode deferredNode : deferred) {
if (deferredNode == node) {
int deferFunctions = fDeferFunctions;
fDeferFunctions = 0;
try {
deferredNode.accept(this);
} finally {
fDeferFunctions = deferFunctions;
}
deferred.remove(deferredNode);
break;
}
}
}
}
}

View file

@ -44,6 +44,7 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
private CPPNamespaceScope fScope;
private ICPPNamespace fBinding;
private final CPPScopeMapper fScopeMapper= new CPPScopeMapper(this);
private CPPASTAmbiguityResolver fAmbiguityResolver;
public CPPASTTranslationUnit() {
}
@ -190,11 +191,20 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
@Override
public void resolveAmbiguities() {
accept(new CPPASTAmbiguityResolver());
fAmbiguityResolver = new CPPASTAmbiguityResolver();
accept(fAmbiguityResolver);
fAmbiguityResolver = null;
}
@Override
protected IType createType(IASTTypeId typeid) {
return CPPVisitor.createType(typeid);
}
@Override
public void resolvePendingAmbiguities(IASTNode node) {
if (fAmbiguityResolver != null) {
fAmbiguityResolver.resolvePendingAmbiguities(node);
}
}
}

View file

@ -680,6 +680,9 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
static ICPPEvaluation getReturnExpression(IASTFunctionDefinition functionDefinition) {
IASTReturnStatement returnStatement = null;
// Make sure ambiguity resolution has been performed on the function body, even
// if it's a class method and we're still processing the class declaration.
((ASTNode) functionDefinition).resolvePendingAmbiguities();
IASTStatement body = functionDefinition.getBody();
if (body instanceof IASTReturnStatement) {
returnStatement = (IASTReturnStatement) body;