1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Bug 515453 - Clear all ProblemBindings stored during ambiguity resolution

This prevents names getting incorrectly stuck with ProblemBindings
created at a time when the AST wasn't fully ambiguity-resolved yet.

Change-Id: Ibca4a774ee26c393bf2b6decb535b82a2329caad
This commit is contained in:
Nathan Ridge 2017-04-23 17:27:53 -04:00
parent 6edd1c6a53
commit 87db7de765
2 changed files with 36 additions and 0 deletions

View file

@ -9867,6 +9867,23 @@ public class AST2TemplateTests extends AST2TestBase {
public void testAmbiguityResolutionInNestedClassMethodBody_485388() throws Exception {
parseAndCheckBindings();
}
// template <typename...>
// struct Voider {
// using type = void;
// };
//
// template <typename... Args>
// using void_t = typename Voider<Args...>::type;
//
// template <typename, template <typename...> class Op, typename... Args>
// struct IsDetectedImpl;
//
// template <template <typename...> class Op, typename... Args>
// struct IsDetectedImpl<void_t<Op<Args...>>, Op, Args...> {};
public void testAmbiguityResolution_515453() throws Exception {
parseAndCheckBindings();
}
// template<typename T, T v>
// struct F {

View file

@ -16,6 +16,7 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
@ -23,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit;
@ -204,10 +206,27 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
fScopeMapper.handleAdditionalDirectives(scope);
}
private class ProblemBindingClearer extends ASTVisitor {
public ProblemBindingClearer() {
shouldVisitNames = true;
}
@Override
public int visit(IASTName name) {
if (name.getBinding() instanceof IProblemBinding) {
name.setBinding(null);
}
return PROCESS_CONTINUE;
}
}
@Override
public void resolveAmbiguities() {
fAmbiguityResolver = new CPPASTAmbiguityResolver();
accept(fAmbiguityResolver);
// During ambiguity resolution, names can incorrectly get stuck with ProblemBindings.
// To prevent this, clear all ProblemBindings here, allowing name resolution for
// the affected names to be attempted again with a fully ambiguity-resolved AST.
accept(new ProblemBindingClearer());
fAmbiguityResolver = null;
}