From 4eb24e010993b2d9152c2038566f0114fd65fac7 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 14 Jun 2016 16:18:34 -0400 Subject: P0145R2: Refining Expression Order for C++. gcc/c-family/ * c.opt (fargs-in-order): New. * c-opts.c (c_common_post_options): Adjust flag_args_in_order. gcc/cp/ * cp-tree.h (CALL_EXPR_OPERATOR_SYNTAX, CALL_EXPR_ORDERED_ARGS) (CALL_EXPR_REVERSE_ARGS): New. * call.c (build_new_op_1): Set them. (extract_call_expr, op_is_ordered): New. (build_over_call): Set CALL_EXPR_ORDERED_ARGS. * cp-gimplify.c (cp_gimplify_expr) [CALL_EXPR]: Handle new flags. * pt.c (tsubst_copy_and_build): Copy new flags. * semantics.c (simplify_aggr_init_expr): Likewise. * tree.c (build_aggr_init_expr): Likewise. (build_min_non_dep_op_overload): Likewise. From-SVN: r237459 --- gcc/testsuite/g++.dg/cpp1z/eval-order1.C | 21 +++++ gcc/testsuite/g++.dg/cpp1z/eval-order2.C | 15 ++++ gcc/testsuite/g++.dg/cpp1z/eval-order3.C | 150 +++++++++++++++++++++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1z/eval-order1.C create mode 100644 gcc/testsuite/g++.dg/cpp1z/eval-order2.C create mode 100644 gcc/testsuite/g++.dg/cpp1z/eval-order3.C (limited to 'gcc/testsuite') diff --git a/gcc/testsuite/g++.dg/cpp1z/eval-order1.C b/gcc/testsuite/g++.dg/cpp1z/eval-order1.C new file mode 100644 index 0000000..278990d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/eval-order1.C @@ -0,0 +1,21 @@ +// P0145R2: Refining Expression Order for C++ +// { dg-do run } +// { dg-options "-std=c++1z" } + +extern "C" int printf (const char *, ...); +void sink(...) { } + +int last = 0; +int f(int i) +{ + if (i < last) + __builtin_abort (); + last = i; + return i; +} + +int main() +{ + sink(f(1), f(2)); + sink(f(3), f(4), f(5)); +} diff --git a/gcc/testsuite/g++.dg/cpp1z/eval-order2.C b/gcc/testsuite/g++.dg/cpp1z/eval-order2.C new file mode 100644 index 0000000..2a741d6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/eval-order2.C @@ -0,0 +1,15 @@ +// P0145R2: Refining Expression Order for C++ +// { dg-do run } +// { dg-options "-std=c++1z" } + +#include +#define assert(X) if (!(X)) __builtin_abort(); + +int main() +{ + std::string s = "but I have heard it works even if you don't believe in it" ; + s.replace(0, 4, "" ).replace( s.find( "even" ), 4, "only" ) + .replace( s.find( " don't" ), 6, "" ); + + assert( s == "I have heard it works only if you believe in it" ) ; +} diff --git a/gcc/testsuite/g++.dg/cpp1z/eval-order3.C b/gcc/testsuite/g++.dg/cpp1z/eval-order3.C new file mode 100644 index 0000000..15df903 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/eval-order3.C @@ -0,0 +1,150 @@ +// P0145R2: Refining Expression Order for C++ +// { dg-do run } +// { dg-options "-std=c++1z -fargs-in-order=1" } + +extern "C" int printf (const char *, ...); +void sink(...) { } + +int last = 0; +int f(int i) +{ + if (i < last) + __builtin_abort (); + last = i; + return i; +} + +int& g(int i) +{ + static int dummy; + f(i); + return dummy; +} + +struct A +{ + int _i; + A(int i): _i(f(i)) { } + A& memfn(int i, int j) { f(j); return *this; } + int operator<<(int i) { } + A& operator=(const A&) { return *this; } + A& operator+=(int i) { return *this; } +}; + +int operator>>(A&, int i) { } + +A a(0); +A* afn(int i) +{ + f(i); + return &a; +} + +A& aref(int i) +{ + f(i); + return a; +} + +static int si; +int* ip (int i) +{ + f(i); + return &si; +} + +int& iref(int i) +{ + f(i); + return si; +} + +auto pmff(int i) { + f(i); + return &A::memfn; +} + +template void f() +{ + // a.b + A(1).memfn(f(2),3).memfn(f(4),5); + aref(6).memfn(f(7),8); + (aref(9).*pmff(10))(f(11),12); + last = 0; + + // a->b + afn(12)->memfn(f(13),14); + + // a->*b + (afn(15)->*pmff(16))(f(17),18); + last = 0; + + // a(b) + // covered in eval-order1.C + + // b @= a + aref(19)=A(18); + //iref(21)=f(20); + aref(23)+=f(22); + last = 0; + + // a[b] + afn(20)[f(21)-21].memfn(f(22),23); + ip(24)[f(25)-25] = 0; + last=0; + + // a << b + aref(24) << f(25); + iref(26) << f(27); + last=0; + + // a >> b + aref(26) >> f(27); + iref(28) >> f(29); +} + +void g() +{ + // a.b + A(1).memfn(f(2),3).memfn(f(4),5); + aref(6).memfn(f(7),8); + (aref(9).*pmff(10))(f(11),12); + last = 0; + + // a->b + afn(12)->memfn(f(13),14); + + // a->*b + (afn(15)->*pmff(16))(f(17),18); + last = 0; + + // a(b) + // covered in eval-order1.C + + // b @= a + aref(19)=A(18); + //iref(21)=f(20); + aref(23)+=f(22); + last = 0; + + // a[b] + afn(20)[f(21)-21].memfn(f(22),23); + ip(24)[f(25)-25] = 0; + last=0; + + // a << b + aref(24) << f(25); + iref(26) << f(27); + last=0; + + // a >> b + aref(26) >> f(27); + iref(28) >> f(29); +} + +int main() +{ + g(); + last = 0; + f(); +} -- cgit v1.1