From 450504e50503876b0434b73733ea83e963fce6ac Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Thu, 13 Mar 2014 20:39:01 -0700 Subject: [PATCH] Bug 430230. More involved test case and a fix for the issues it uncovered. --- .../parser/tests/ast2/AST2TemplateTests.java | 54 ++++++++++++++++++- .../parser/cpp/semantics/CPPEvaluation.java | 16 ++++++ .../dom/parser/cpp/semantics/EvalComma.java | 12 +---- .../dom/parser/cpp/semantics/EvalTypeId.java | 14 ++--- 4 files changed, 73 insertions(+), 23 deletions(-) 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 d09424f3ced..15a79313732 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 @@ -7381,7 +7381,7 @@ public class AST2TemplateTests extends AST2TestBase { public void testSfinaeWhenResolvingAddressOfFunction_429928() throws Exception { parseAndCheckBindings(); } - + // template // struct A {}; // @@ -7430,7 +7430,57 @@ public class AST2TemplateTests extends AST2TestBase { // int waldo(int p); // // int x = waldo(test(0)); - public void testSfinaeInNewExpression_430230() throws Exception { + public void testSfinaeInNewExpression_430230a() throws Exception { + parseAndCheckBindings(); + } + + // template + // struct bool_constant { + // static constexpr bool value = __v; + // }; + // + // typedef bool_constant true_type; + // typedef bool_constant false_type; + // + // struct B { + // template + // static true_type test(int); + // + // template + // static false_type test(...); + // }; + // + // template + // struct C : public B { + // typedef decltype(test(0)) type; + // }; + // + // template + // struct D : public C::type {}; + // + // template + // struct E : public bool_constant::value> {}; + // + // template + // struct enable_if {}; + // + // template + // struct enable_if { + // typedef T type; + // }; + // + // struct A {}; + // + // template + // typename enable_if::type + // waldo(); + // + // template + // typename enable_if::value>::type + // waldo(); + // + // auto x = waldo; + public void testSfinaeInNewExpression_430230b() throws Exception { parseAndCheckBindings(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java index 99d2bf6d6c2..1f394567257 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java @@ -73,4 +73,20 @@ public abstract class CPPEvaluation implements ICPPEvaluation { } return binding; } + + public static boolean containsDependentType(ICPPEvaluation[] evaluations) { + for (ICPPEvaluation eval : evaluations) { + if (eval.isTypeDependent()) + return true; + } + return false; + } + + public static boolean containsDependentValue(ICPPEvaluation[] evaluations) { + for (ICPPEvaluation eval : evaluations) { + if (eval.isValueDependent()) + return true; + } + return false; + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java index d9c75fa12a0..b405d0596b7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalComma.java @@ -65,20 +65,12 @@ public class EvalComma extends CPPDependentEvaluation { if (fType != null) return fType instanceof TypeOfDependentExpression; - for (ICPPEvaluation arg : fArguments) { - if (arg.isTypeDependent()) - return true; - } - return false; + return containsDependentType(fArguments); } @Override public boolean isValueDependent() { - for (ICPPEvaluation arg : fArguments) { - if (arg.isValueDependent()) - return true; - } - return false; + return containsDependentValue(fArguments); } public ICPPFunction[] getOverloads(IASTNode point) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java index 2cafbca4d6f..2975dd9e059 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java @@ -93,7 +93,7 @@ public class EvalTypeId extends CPPDependentEvaluation { } private IType computeType() { - if (CPPTemplates.isDependentType(fInputType)) + if (CPPTemplates.isDependentType(fInputType) || containsDependentType(fArguments)) return new TypeOfDependentExpression(this); IType type = typeFromReturnType(fInputType); @@ -186,14 +186,14 @@ public class EvalTypeId extends CPPDependentEvaluation { if (args == fArguments && type == fInputType) return this; - if (!CPPTemplates.isDependentType(type) && !areArgumentTypesDependent() && type instanceof ICPPClassType) { + if (!CPPTemplates.isDependentType(type) && !containsDependentType(args) && type instanceof ICPPClassType) { // Check the constructor call and return EvalFixed.INCOMPLETE to indicate a substitution // failure if the call cannot be resolved. ICPPClassType classType = (ICPPClassType) type; LookupData data = new LookupData(classType.getNameCharArray(), null, point); ICPPConstructor[] constructors = ClassTypeHelper.getConstructors(classType, point); data.foundItems = constructors; - data.setFunctionArguments(false, fArguments); + data.setFunctionArguments(false, args); try { IBinding binding = CPPSemantics.resolveFunction(data, constructors, true); if (binding == null || binding instanceof IProblemBinding || @@ -244,12 +244,4 @@ public class EvalTypeId extends CPPDependentEvaluation { } return false; } - - private boolean areArgumentTypesDependent() { - for (ICPPEvaluation arg : fArguments) { - if (arg.isTypeDependent()) - return true; - } - return false; - } }