From 654907174b0c46e16b319be604a553ab05b19651 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Thu, 25 Aug 2016 21:18:19 -0400 Subject: [PATCH] Bug 497668 - Avoid unnecessary name resolution during ambiguity resolution Since resolved bindings are cached, we can get stuck with a bad binding resolved during an incorrecy branch of ambiguity resolution. Change-Id: I59bcb9f6f2b756892a56b135e8d6a1f026180728 --- .../parser/tests/ast2/AST2TemplateTests.java | 23 +++++++++++++++++++ .../parser/cpp/CPPASTTemplateIDAmbiguity.java | 7 +++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index e0aad1d4818..77519c53db8 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -6239,6 +6239,29 @@ public class AST2TemplateTests extends AST2TestBase { public void testTemplateIDAmbiguity_445177() throws Exception { parseAndCheckBindings(); } + + // template + // struct EnableIf; + // + // template + // struct EnableIf { + // typedef T type; + // }; + // + // template struct Tuple; + // + // template struct TupleSize; + // + // template + // struct TupleSize> { + // static constexpr int value = sizeof...(E); + // }; + // + // template + // using W = typename EnableIf<(I < TupleSize>::value), int>::type; + public void testTemplateIDAmbiguity_497668() throws Exception { + parseAndCheckBindings(); + } // template void foo(T); // template void foo(T, typename T::type* = 0); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateIDAmbiguity.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateIDAmbiguity.java index 6b5931de81b..091b8fe198e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateIDAmbiguity.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateIDAmbiguity.java @@ -114,7 +114,12 @@ public class CPPASTTemplateIDAmbiguity extends ASTAmbiguousNode int count= 0; for (IASTName templateName : templateNames) { if (templateName.getTranslationUnit() != null) { - IBinding b= templateName.resolveBinding(); + // It's sufficient to perform the first phase of binding resolution here, + // because template names should never resolve to two-phase bindings. + // The second phase of binding resolution, when performed for an incorrect + // variant, can cause incorrect bindings to be cached in places where they + // are hard to clear. + IBinding b= templateName.resolvePreBinding(); if (b instanceof IProblemBinding) { if (!containsFunctionTemplate(((IProblemBinding) b).getCandidateBindings())) return -1;