On 6/25/26 9:36 AM, Jakub Jelinek wrote:
Hi!
I believe we already implement the P3847R1 - Lexical order for lambdas
paper, after all it is part of the ABI.
So, this patch just adds tests to verify that, so that we can mark this
as implemented (I'd say just Yes, even GCC 4.6 passes the second test
with -std=c++0x and GCC 4.8 with -std=c++1y the first test).
Tested on x86_64-linux and i686-linux, ok for trunk?
2026-06-25 Jakub Jelinek <[email protected]>
PR c++/125832
* g++.dg/cpp29/lambda-order1.C: New test.
* g++.dg/cpp29/lambda-order2.C: New test.
--- gcc/testsuite/g++.dg/cpp29/lambda-order1.C.jj 2026-06-25
14:56:40.172841476 +0200
+++ gcc/testsuite/g++.dg/cpp29/lambda-order1.C 2026-06-25 15:19:51.255756927
+0200
@@ -0,0 +1,42 @@
+// P3847R1 - Lexical order for lambdas
+// { dg-do run { target c++14 } }
+
+int e;
+
+int
+foo (int x)
+{
+ if (x != e)
+ __builtin_abort ();
+ ++e;
+ return x;
+}
+
+int
+main ()
+{
+ int a = 1;
+ long b = 2;
+ double c = 3;
+ short d = 4;
+ foo (0);
+ auto f = [&, a0 = foo (1), a, a1 = foo (2),
Why include the implicit by-ref capture of d when its ordering is still
unspecified (and not tested)? It doesn't hurt, but could use a comment.
This test should probably also check order of initialization of by-ref
init-capture.
+ b0 = foo (3), b, b1 = foo (4),
+ c0 = foo (5), c, c1 = foo (6)] () {
+ if (&a0 >= &a
+ || &a >= &a1
+ || (const void *) &a1 >= (const void *) &b0
+ || (const void *) &b0 >= (const void *) &b
+ || d != 4
+ || (const void *) &b >= (const void *) &b1
+ || (const void *) &b1 >= (const void *) &c0
+ || (const void *) &c0 >= (const void *) &c
+ || (const void *) &c >= (const void *) &c1)
+ __builtin_abort ();
+ };
+ foo (7);
+ f ();
+ foo (8);
+ f ();
+ foo (9);
+}
--- gcc/testsuite/g++.dg/cpp29/lambda-order2.C.jj 2026-06-25
14:56:58.261618750 +0200
+++ gcc/testsuite/g++.dg/cpp29/lambda-order2.C 2026-06-25 15:05:16.811488142
+0200
@@ -0,0 +1,19 @@
+// P3847R1 - Lexical order for lambdas
+// { dg-do run { target c++11 } }
+
+int
+main ()
+{
+ int a = 1;
+ long b = 2;
+ double c = 3;
+ short d = 4;
+ auto f = [&, a, b, c] () {
+ if ((const void *) &a >= (const void *) &b
+ || d != 4
+ || (const void *) &b >= (const void *) &c)
+ __builtin_abort ();
+ };
+ f ();
+ f ();
+}
Jakub