1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 302412: Additional testcases + fix for direct initialization.

This commit is contained in:
Markus Schorn 2010-03-15 13:23:15 +00:00
parent 1e60031409
commit e5da8307a0
4 changed files with 50 additions and 34 deletions

View file

@ -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 extends IBinding> T assertNonProblem(String section, int len) {

View file

@ -8085,7 +8085,7 @@ public class AST2CPPTests extends AST2BaseTest {
// complex(const T& r, const T& i);
// };
// template<typename T> struct vector {
// vector(std::initializer_list<T>);
// vector(std::initializer_list<T>){};
// };
// 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<typename T> 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);
}
}

View file

@ -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;

View file

@ -150,10 +150,6 @@ class Cost {
fCouldNarrow= false;
}
public ICPPFunction getUserDefinedConversion() {
return fUserDefinedConversion;
}
/**
* Returns an integer &lt 0 if other cost is <code>null</code>, or this cost is smaller than the other cost,
* 0 if this cost is equal to the other cost,