On Wed, May 06, 2026 at 03:56:54PM -0400, Jason Merrill wrote:
> On 5/6/26 8:38 AM, Marek Polacek wrote:
> > On Wed, May 06, 2026 at 10:24:50AM +0200, Jakub Jelinek wrote:
> > > Hi!
> > >
> > > I think a USING_STMT operand shouldn't count as consteval-only use.
> > >
> > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> >
> > Looks ok to me.
>
> Should this be in check_out_of_consteval_use_r instead?
>
> I'm unclear on the recursion model of the walk over that function vs. the
> call to check_out_of_consteval_use in cp_fold_immediate_r. Are we visiting
> statements too many times?
It is unclear to me too. E.g. cp-gimplify.cc is calling it on each
statement, but then a statement can be a = ({ using std::meta::info; 42; });
too and I think we'd walk into USING_STMT in that case.
So, I think it is safer to do this indeed in check_out_of_consteval_use_r.
Tested on x86_64-linux, ok for trunk?
2026-05-07 Jakub Jelinek <[email protected]>
PR c++/125184
* reflect.cc (check_out_of_consteval_use_r): Don't walk children of
USING_STMTs.
* g++.dg/reflect/using3.C: New test.
--- gcc/cp/reflect.cc.jj 2026-05-07 11:06:45.008764113 +0200
+++ gcc/cp/reflect.cc 2026-05-07 12:16:38.426947482 +0200
@@ -8716,6 +8716,8 @@ check_out_of_consteval_use_r (tree *tp,
|| TREE_CODE (t) == INIT_EXPR
/* And don't recurse on DECL_EXPRs. */
|| TREE_CODE (t) == DECL_EXPR
+ /* Neither into USING_STMT. */
+ || TREE_CODE (t) == USING_STMT
/* Blocks can appear in the TREE_VEC operand of OpenMP
depend/affinity/map/to/from OMP_CLAUSEs when using iterators. */
|| TREE_CODE (t) == BLOCK)
--- gcc/testsuite/g++.dg/reflect/using3.C.jj 2026-05-07 12:15:42.728757888
+0200
+++ gcc/testsuite/g++.dg/reflect/using3.C 2026-05-07 12:15:42.728757888
+0200
@@ -0,0 +1,11 @@
+// PR c++/125184
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+#include <meta>
+
+void
+foo ()
+{
+ using std::meta::info;
+}
Jakub