From 665f47395e441584cc79fa1955a77ba1411f6665 Mon Sep 17 00:00:00 2001 From: Hannes Vogt Date: Tue, 30 Apr 2019 22:53:43 +0200 Subject: [PATCH] Bug 546843 - Initialization from dependent argument Create deferred functions for constructor calls with dependent arguments. Change-Id: I007dd4fd12c13acdcb39225b73051589f6dafad3 Signed-off-by: Hannes Vogt --- .../core/parser/tests/ast2/AST2CPPTests.java | 34 +++++++++++++++++++ .../parser/cpp/semantics/CPPSemantics.java | 14 ++++++++ 2 files changed, 48 insertions(+) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 94c9023c58c..134cc592ab3 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -13101,4 +13101,38 @@ public class AST2CPPTests extends AST2CPPTestBase { BindingAssertionHelper bh = getAssertionHelper(); bh.assertImplicitName("foo", 3, IProblemBinding.class); } + + // class Time { + // }; + // + // template + // class Test { + // private: + // T t; + // public: + // void test() { + // Time time = t.get(); + // } + // }; + public void testCopyInitializationFromDependentType_546843() throws Exception { + parseAndCheckImplicitNameBindings(); + } + + // class Time { + // int a; + // }; + // + // template + // class Test { + // private: + // T t; + // public: + // void test() { + // Time time{t.get()}; + // } + // }; + public void testListInitializationFromDependentType_546843() throws Exception { + parseAndCheckImplicitNameBindings(); + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index e899187cc0d..2b20779a8fc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -3726,6 +3726,11 @@ public class CPPSemantics { IType sourceType = evaluation.getType(); ValueCategory isLValue = evaluation.getValueCategory(); if (sourceType != null) { + if (CPPTemplates.isDependentType(sourceType)) { + IType[] tmp = { sourceType }; + setTargetedFunctionsToUnknown(tmp); + return CPPDeferredFunction.createForCandidates(type.getConstructors()); + } Cost c; if (calculateInheritanceDepth(sourceType, type) >= 0) { c = Conversions.copyInitializationOfClass(isLValue, sourceType, type, false); @@ -3747,6 +3752,15 @@ public class CPPSemantics { // List initialization. ICPPEvaluation eval = ((ICPPASTInitializerClause) initializer).getEvaluation(); if (eval instanceof EvalInitList) { + if (CPPTemplates.isDependentType(eval.getType())) { + ICPPEvaluation[] clauses = ((EvalInitList) eval).getClauses(); + IType[] tmp = new IType[clauses.length]; + for (int i = 0; i < clauses.length; i++) { + tmp[i] = clauses[i].getType(); + } + setTargetedFunctionsToUnknown(tmp); + return CPPDeferredFunction.createForCandidates(type.getConstructors()); + } Cost c = Conversions.listInitializationSequence((EvalInitList) eval, type, UDCMode.ALLOWED, true); if (c.converts()) { ICPPFunction f = c.getUserDefinedConversion();