[5/5] c++/reflection: Fix missing return before throw_exception

Message ID 20260407110826.8427-5-yangkun@disroot.org
State Committed
Commit 4977528639c683109dbfb9a2187000f8b2cc1ae2
Headers
Series [1/5] c++: gcc_assert(false) replaced with gcc_unreachable() |

Commit Message

yangkun April 7, 2026, 11:08 a.m. UTC
  gcc/cp/ChangeLog:
	* reflect.cc (eval_current_function): Add missing return.
	(eval_current_class): Likewise.
---
 gcc/cp/reflect.cc | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
  

Comments

Jakub Jelinek April 7, 2026, 3:51 p.m. UTC | #1
On Tue, Apr 07, 2026 at 07:08:26PM +0800, Yang Kun wrote:
> gcc/cp/ChangeLog:
> 	* reflect.cc (eval_current_function): Add missing return.
> 	(eval_current_class): Likewise.
> ---
>  gcc/cp/reflect.cc | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc
> index 1f8a7800f..07dd0103e 100644
> --- a/gcc/cp/reflect.cc
> +++ b/gcc/cp/reflect.cc
> @@ -6441,8 +6441,9 @@ eval_current_function (location_t loc, const constexpr_ctx *ctx,
>    tree scope = reflect_current_scope (loc, ctx, call, non_constant_p,
>  				      "std::meta::current_function");
>    if (TREE_CODE (scope) != FUNCTION_DECL)
> -    throw_exception (loc, ctx, "current scope does not represent a function",
> -		     fun, non_constant_p, jump_target);
> +    return throw_exception (loc, ctx,
> +			    "current scope does not represent a function",
> +			    fun, non_constant_p, jump_target);
>    return get_reflection_raw (loc, scope);
>  }
>  
> @@ -6460,9 +6461,10 @@ eval_current_class (location_t loc, const constexpr_ctx *ctx,
>        && TYPE_P (DECL_CONTEXT (scope)))
>      scope = DECL_CONTEXT (scope);
>    if (!CLASS_TYPE_P (scope))
> -    throw_exception (loc, ctx, "current scope does not represent a class"
> -			       " nor a member function",
> -		     fun, non_constant_p, jump_target);
> +    return throw_exception (loc, ctx,
> +			    "current scope does not represent a class"
> +			    " nor a member function",
> +			    fun, non_constant_p, jump_target);
>    return get_reflection_raw (loc, scope);
>  }

LGTM, but same legal question applies.

	Jakub
  

Patch

diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc
index 1f8a7800f..07dd0103e 100644
--- a/gcc/cp/reflect.cc
+++ b/gcc/cp/reflect.cc
@@ -6441,8 +6441,9 @@  eval_current_function (location_t loc, const constexpr_ctx *ctx,
   tree scope = reflect_current_scope (loc, ctx, call, non_constant_p,
 				      "std::meta::current_function");
   if (TREE_CODE (scope) != FUNCTION_DECL)
-    throw_exception (loc, ctx, "current scope does not represent a function",
-		     fun, non_constant_p, jump_target);
+    return throw_exception (loc, ctx,
+			    "current scope does not represent a function",
+			    fun, non_constant_p, jump_target);
   return get_reflection_raw (loc, scope);
 }
 
@@ -6460,9 +6461,10 @@  eval_current_class (location_t loc, const constexpr_ctx *ctx,
       && TYPE_P (DECL_CONTEXT (scope)))
     scope = DECL_CONTEXT (scope);
   if (!CLASS_TYPE_P (scope))
-    throw_exception (loc, ctx, "current scope does not represent a class"
-			       " nor a member function",
-		     fun, non_constant_p, jump_target);
+    return throw_exception (loc, ctx,
+			    "current scope does not represent a class"
+			    " nor a member function",
+			    fun, non_constant_p, jump_target);
   return get_reflection_raw (loc, scope);
 }