diff options
author | Markus Schorn | 2009-11-24 10:53:12 +0000 |
---|---|---|
committer | Markus Schorn | 2009-11-24 10:53:12 +0000 |
commit | 99148105b37df9699bdb5b4751f1ce2423318825 (patch) | |
tree | cb4a1315469adae4b6f4635d891d916554decd5d /core/org.eclipse.cdt.core.tests | |
parent | 042f47dbef3e695a8aa7cf028587807236444308 (diff) | |
download | org.eclipse.cdt-99148105b37df9699bdb5b4751f1ce2423318825.tar.gz org.eclipse.cdt-99148105b37df9699bdb5b4751f1ce2423318825.tar.xz org.eclipse.cdt-99148105b37df9699bdb5b4751f1ce2423318825.zip |
RValue References: Implementation and testcases, bug 294730.
Diffstat (limited to 'core/org.eclipse.cdt.core.tests')
3 files changed, 199 insertions, 2 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ASTComparer.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ASTComparer.java index 6110daeb3cd..6c329290f07 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ASTComparer.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ASTComparer.java @@ -51,7 +51,8 @@ public class ASTComparer extends Assert { "isReference", "isAssociatedWithLastName", "getNestingLevel", - "getImplicitNames" + "getImplicitNames", + "isLValue" )); 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 cfdd619ff64..82bf53d2ca3 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 @@ -23,6 +23,7 @@ import java.util.Iterator; import junit.framework.TestSuite; import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; @@ -7750,5 +7751,157 @@ public class AST2CPPTests extends AST2BaseTest { final String code= getAboveComment(); parseAndCheckBindings(code, ParserLanguage.CPP); } + + // struct A {}; + // + // void foo(const A&); // #1 + // void foo(A&&); // #2 + // + // A source_rvalue(); + // A& source_ref(); + // A&& source_rvalue_ref(); + // + // const A source_const_rvalue(); + // const A& source_const_ref(); + // const A&& source_const_rvalue_ref(); + // + // int main() { + // A a; + // A& ra = a; + // A&& rra = a; + // const A ca; + // const A& rca = ca; + // const A&& rrca = ca; + // + // foo(a); // #1 + // foo(ra); // #1 + // foo(rra); // #1 + // foo(ca); // #1 + // foo(rca); // #1 + // foo(rrca); // #1 + // foo(source_rvalue()); // #2 + // foo(source_ref()); // #1 + // foo(source_rvalue_ref()); // #2 + // foo(source_const_rvalue()); // #1 + // foo(source_const_ref()); // #1 + // foo(source_const_rvalue_ref()); // #1 + // } + public void testRValueReference_294730() throws Exception { + final String code= getAboveComment(); + BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + IBinding foo1= bh.assertNonProblem("foo(const A&)", 3); + IBinding foo2= bh.assertNonProblem("foo(A&&)", 3); + IBinding b; + b= bh.assertNonProblem("foo(a)", 3); + assertSame(b, foo1); + b= bh.assertNonProblem("foo(ra)", 3); + assertSame(b, foo1); + b= bh.assertNonProblem("foo(rra)", 3); + assertSame(b, foo1); + b= bh.assertNonProblem("foo(ca)", 3); + assertSame(b, foo1); + b= bh.assertNonProblem("foo(rca)", 3); + assertSame(b, foo1); + b= bh.assertNonProblem("foo(rrca)", 3); + assertSame(b, foo1); + b= bh.assertNonProblem("foo(source_rvalue())", 3); + assertSame(b, foo2); + b= bh.assertNonProblem("foo(source_ref())", 3); + assertSame(b, foo1); + b= bh.assertNonProblem("foo(source_rvalue_ref())", 3); + assertSame(b, foo2); + b= bh.assertNonProblem("foo(source_const_rvalue())", 3); + assertSame(b, foo1); + b= bh.assertNonProblem("foo(source_const_ref())", 3); + assertSame(b, foo1); + b= bh.assertNonProblem("foo(source_const_rvalue_ref())", 3); + assertSame(b, foo1); + } + + + // int i; + // typedef int& LRI; + // typedef int&& RRI; + // LRI& r1 = i; // r1 has the type int& + // const LRI& r2 = i; // r2 has the type int& + // const LRI&& r3 = i; // r3 has the type int& + // RRI& r4 = i; // r4 has the type int& + // RRI&& r5 = i; // r5 has the type int&& + public void testRValueReferenceTypedefs_294730() throws Exception { + final String code= getAboveComment(); + BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + IVariable v; + v= bh.assertNonProblem("r1", 2); + assertEquals("int &", ASTTypeUtil.getType(v.getType())); + v= bh.assertNonProblem("r2", 2); + assertEquals("int &", ASTTypeUtil.getType(v.getType())); + v= bh.assertNonProblem("r3", 2); + assertEquals("int &", ASTTypeUtil.getType(v.getType())); + v= bh.assertNonProblem("r4", 2); + assertEquals("int &", ASTTypeUtil.getType(v.getType())); + v= bh.assertNonProblem("r5", 2); + assertEquals("int &&", ASTTypeUtil.getType(v.getType())); + } + + // void dref(double&); + // void drref(double&&); + // void cdref(const double&); + // struct A { }; + // struct B : A { }; + // extern B f(); + // struct X { + // operator B(); + // } x; + // void aref(A&); + // void caref(const A&); + // void carref(const A&&); + // void test() { + // B b; + // double d = 2.0; + // const volatile double cvd = 1; + // int i = 2; + // dref(d); + // cdref(d); + // aref(b); + // caref(b); + // dref(2.0); // error: not an lvalue and reference not const + // dref(i); // error: type mismatch and reference not const + // drref(i); // error: rvalue reference cannot bind to lvalue + // caref(f()); // bound to the A subobject of the B rvalue. + // carref(f()); // same as above + // caref(x); // bound to the A subobject of the result of the conversion + // cdref(2); // rcd2 refers to temporary with value 2.0 + // drref(2); // rcd3 refers to temporary with value 2.0 + // cdref(cvd); // error: type qualifiers dropped + // } + public void testDirectBinding_294730() throws Exception { + final String code= getAboveComment(); + BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + bh.assertNonProblem("dref(d)", 4); + bh.assertNonProblem("cdref(d)", 5); + bh.assertNonProblem("aref(b)", 4); + bh.assertNonProblem("caref(b)", 5); + bh.assertProblem("dref(2.0)", 4); + bh.assertProblem("dref(i)", 4); + bh.assertProblem("drref(i)", 5); + bh.assertNonProblem("caref(f())", 5); + bh.assertNonProblem("carref(f())", 6); + bh.assertNonProblem("caref(x)", 5); + bh.assertNonProblem("cdref(2)", 5); + bh.assertNonProblem("drref(2)", 5); + bh.assertProblem("cdref(cvd)", 5); + } + + // struct S { + // operator int() {return 0;} + // }; + // S s(){return *new S();} + // void test(int) { + // test(s()); + // } + public void testSpecialRuleForImplicitObjectType_294730() throws Exception { + final String code= getAboveComment(); + parseAndCheckBindings(code, ParserLanguage.CPP); + } } 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 fba9cb3f342..1daabe62459 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 @@ -4296,8 +4296,51 @@ public class AST2TemplateTests extends AST2BaseTest { // int a=1; // a OPASSIGN(>>) 1; // } - public void testTokenPasteShiftROperaotr_261268() throws Exception { + public void testTokenPasteShiftROperator_261268() throws Exception { final String code= getAboveComment(); parseAndCheckBindings(code, ParserLanguage.CPP); } + + // template <class T> class X { + // void f(const T&); + // void g(T&&); + // }; + // X<int&> x1; // X<int&>::f has the parameter type int& + // // X<int&>::g has the parameter type int& + // X<const int&&> x2; // X<const int&&>::f has the parameter type const int& + // // X<const int&&>::g has the parameter type const int&& + public void testRValueReferences_1_294730() throws Exception { + final String code= getAboveComment(); + parseAndCheckBindings(code, ParserLanguage.CPP); + BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + + ICPPClassType type= bh.assertNonProblem("X<int&>", 7); + ICPPMethod[] ms= type.getMethods(); + int i= ms[0].getName().equals("f") ? 0 : 1; + ICPPMethod m= ms[i]; + assertEquals("int &", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); + m= ms[1-i]; + assertEquals("int &", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); + + type= bh.assertNonProblem("X<const int&&>", 14); + ms= type.getMethods(); + i= ms[0].getName().equals("f") ? 0 : 1; + m= ms[i]; + assertEquals("const int &", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); + m= ms[1-i]; + assertEquals("const int &&", ASTTypeUtil.getType(m.getType().getParameterTypes()[0])); + } + + // template<typename T> int f(T&&); + // void test() { + // int i; + // int j = f(i); // calls f<int&>(i) + // } + public void testRValueReferences_2_294730() throws Exception { + final String code= getAboveComment(); + parseAndCheckBindings(code, ParserLanguage.CPP); + BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + ICPPTemplateInstance inst= bh.assertNonProblem("f(i)", 1); + assertEquals("<int &>", ASTTypeUtil.getArgumentListString(inst.getTemplateArguments(), true)); + } } |