diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java index 9166c6f7b1d..07ac9f39c12 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java @@ -492,13 +492,13 @@ public class AST2BaseTest extends BaseTestCase { return tu; } - public IBinding assertProblem(String section, int len) { + public IProblemBinding assertProblem(String section, int len) { if (len <= 0) len= section.length()-len; IBinding binding= binding(section, len); assertTrue("Non-ProblemBinding for name: " + section.substring(0, len), binding instanceof IProblemBinding); - return binding; + return (IProblemBinding) binding; } public T assertNonProblem(String section, int len) { 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 fb9255df6d5..b6b79a463f7 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 @@ -8085,7 +8085,7 @@ public class AST2CPPTests extends AST2BaseTest { // complex(const T& r, const T& i); // }; // template struct vector { - // vector(std::initializer_list); + // vector(std::initializer_list){}; // }; // struct str { // str(const char*); @@ -8236,6 +8236,51 @@ public class AST2CPPTests extends AST2BaseTest { bh.assertNonProblem("h( {'a'} )", 1); bh.assertProblem("h( {1.0} )", 1); bh.assertNonProblem("h( { } )", 1); - } + } + + // namespace std { + // template class initializer_list; + // } + // void f(int, int){} + // struct F { F(int,int){}}; + // void fF(F) {} + // + // struct G { G(int){} G(){}}; + // void fG(G) {} + // + // struct H { H(G) {}}; + // void fH(H) {} + // + // void test() { + // f({1,1}); // list is not expanded + // new F({1,1}); // F(1,1) + // fF({1,1}); // F(1,1) + // + // fG(1); // G(1) + // fG({1}); // G(1) + // + // new H(1); // H(G(1)) + // new H({1}); // H(G(1)) or H(H(G(1))) + // fH(1); // no conversion from int to H + // fH({1}); // H(G(1)) + // } + public void testListInitialization_302412f() throws Exception { + ICPPConstructor ctor; + IProblemBinding problem; + String code= getAboveComment(); + BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + bh.assertProblem("f({1,1})", 1); + ctor= bh.assertNonProblem("F({1,1})", 1); + bh.assertNonProblem("fF({1,1})", 2); + + bh.assertNonProblem("fG(1)", 2); + bh.assertNonProblem("fG({1})", 2); + + ctor= bh.assertNonProblem("H(1)", 1); + problem= bh.assertProblem("H({1})", 1); + assertEquals(IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, problem.getID()); + bh.assertProblem("fH(1)", 2); + bh.assertNonProblem("fH({1})", 2); + } } 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 1621e70ba0b..9458efa0d6c 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 @@ -364,7 +364,7 @@ public class CPPSemantics { if (cls instanceof ICPPDeferredClassInstance) { binding= new CPPUnknownConstructor(cls); } else { - binding= selectConstructor(cls, data); + binding= CPPSemantics.resolveFunction(data, cls.getConstructors(), true); } } catch (DOMException e) { return e.getProblem(); @@ -528,31 +528,6 @@ public class CPPSemantics { return false; } - private static IBinding selectConstructor(ICPPClassType cls, LookupData data) throws DOMException { - final IType[] types = data.getFunctionArgumentTypes(); - if (types != null && types.length == 1 && types[0] instanceof InitializerListType) { - Cost cost= Conversions.listInitializationSequence((InitializerListType) types[0], cls, UDCMode.allowUDC, true); - if (cost.converts()) { - if (cost.isAmbiguousUDC()) { - return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, cls.getConstructors()); - } - IBinding result= cost.getUserDefinedConversion(); - if (result == null) { - return cls; - } - return result; - } - return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, cls.getConstructors()); - } - - final ICPPConstructor[] constructors= cls.getConstructors(); - if (constructors.length > 0) { - data.foundItems= constructors; - return CPPSemantics.resolveAmbiguities(data, data.astName); - } - return cls; - } - private static void doKoenigLookup(LookupData data) throws DOMException { data.ignoreUsingDirectives = true; data.forceQualified = true; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Cost.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Cost.java index 5f6c34b4eae..7625acfa24d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Cost.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/Cost.java @@ -150,10 +150,6 @@ class Cost { fCouldNarrow= false; } - public ICPPFunction getUserDefinedConversion() { - return fUserDefinedConversion; - } - /** * Returns an integer < 0 if other cost is null, or this cost is smaller than the other cost, * 0 if this cost is equal to the other cost,