c++: Don't check for consteval-only uses inside of USING_STMT [PR125184]

Message ID afr60nyd3oXBbOc-@tucnak
State New
Headers
Series c++: Don't check for consteval-only uses inside of USING_STMT [PR125184] |

Commit Message

Jakub Jelinek May 6, 2026, 8:24 a.m. UTC
  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?

2026-05-06  Jakub Jelinek  <jakub@redhat.com>

	PR c++/125184
	* reflect.cc (check_out_of_consteval_use): Ignore USING_STMTs.

	* g++.dg/reflect/using3.C: New test.


	Jakub
  

Comments

Marek Polacek May 6, 2026, 12:38 p.m. UTC | #1
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.
 
> 2026-05-06  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c++/125184
> 	* reflect.cc (check_out_of_consteval_use): Ignore USING_STMTs.
> 
> 	* g++.dg/reflect/using3.C: New test.
> 
> --- gcc/cp/reflect.cc.jj	2026-05-05 09:57:59.014541622 +0200
> +++ gcc/cp/reflect.cc	2026-05-05 12:29:03.599363151 +0200
> @@ -8791,6 +8791,9 @@ check_out_of_consteval_use (tree expr, b
>    if (VAR_P (expr) && DECL_DECLARED_CONSTEXPR_P (expr))
>      return false;
>  
> +  if (TREE_CODE (expr) == USING_STMT)
> +    return false;
> +
>    hash_set<tree> pset;
>    if (tree t = cp_walk_tree (&expr, check_out_of_consteval_use_r, &pset, &pset))
>      {
> --- gcc/testsuite/g++.dg/reflect/using3.C.jj	2026-05-05 12:29:58.637468773 +0200
> +++ gcc/testsuite/g++.dg/reflect/using3.C	2026-05-05 12:30:45.345709765 +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
> 

Marek
  
Jason Merrill May 6, 2026, 7:56 p.m. UTC | #2
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?

>> 2026-05-06  Jakub Jelinek  <jakub@redhat.com>
>>
>> 	PR c++/125184
>> 	* reflect.cc (check_out_of_consteval_use): Ignore USING_STMTs.
>>
>> 	* g++.dg/reflect/using3.C: New test.
>>
>> --- gcc/cp/reflect.cc.jj	2026-05-05 09:57:59.014541622 +0200
>> +++ gcc/cp/reflect.cc	2026-05-05 12:29:03.599363151 +0200
>> @@ -8791,6 +8791,9 @@ check_out_of_consteval_use (tree expr, b
>>     if (VAR_P (expr) && DECL_DECLARED_CONSTEXPR_P (expr))
>>       return false;
>>   
>> +  if (TREE_CODE (expr) == USING_STMT)
>> +    return false;
>> +
>>     hash_set<tree> pset;
>>     if (tree t = cp_walk_tree (&expr, check_out_of_consteval_use_r, &pset, &pset))
>>       {
>> --- gcc/testsuite/g++.dg/reflect/using3.C.jj	2026-05-05 12:29:58.637468773 +0200
>> +++ gcc/testsuite/g++.dg/reflect/using3.C	2026-05-05 12:30:45.345709765 +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
>>
> 
> Marek
>
  

Patch

--- gcc/cp/reflect.cc.jj	2026-05-05 09:57:59.014541622 +0200
+++ gcc/cp/reflect.cc	2026-05-05 12:29:03.599363151 +0200
@@ -8791,6 +8791,9 @@  check_out_of_consteval_use (tree expr, b
   if (VAR_P (expr) && DECL_DECLARED_CONSTEXPR_P (expr))
     return false;
 
+  if (TREE_CODE (expr) == USING_STMT)
+    return false;
+
   hash_set<tree> pset;
   if (tree t = cp_walk_tree (&expr, check_out_of_consteval_use_r, &pset, &pset))
     {
--- gcc/testsuite/g++.dg/reflect/using3.C.jj	2026-05-05 12:29:58.637468773 +0200
+++ gcc/testsuite/g++.dg/reflect/using3.C	2026-05-05 12:30:45.345709765 +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;
+}