diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc index 7a87f42fa58..4bfe064c041 100644 --- a/gcc/cp/reflect.cc +++ b/gcc/cp/reflect.cc @@ -3074,7 +3074,9 @@ eval_return_type_of (location_t loc, const constexpr_ctx *ctx, tree r, { if ((eval_is_function (r) != boolean_true_node || !has_type (r, kind)) && eval_is_function_type (r) != boolean_true_node) - return throw_exception_nofn (loc, ctx, fun, non_constant_p, jump_target); + return throw_exception (loc, ctx, "reflection does not represent a " + "function or function type with a return type", + fun, non_constant_p, jump_target); r = MAYBE_BASELINK_FUNCTIONS (r); if (TREE_CODE (r) == FUNCTION_DECL) diff --git a/gcc/testsuite/g++.dg/reflect/return_type_of2.C b/gcc/testsuite/g++.dg/reflect/return_type_of2.C new file mode 100644 index 00000000000..273197eed27 --- /dev/null +++ b/gcc/testsuite/g++.dg/reflect/return_type_of2.C @@ -0,0 +1,20 @@ +// { dg-do compile { target c++26 } } +// { dg-additional-options "-freflection" } +// Test std::meta::return_type_of. + +#include + +using namespace std::meta; + +struct S { + S () { + int a; + constexpr auto r = return_type_of (type_of (parent_of (^^a))); // { dg-error "does not have a type" } + constexpr auto t = return_type_of (parent_of (^^a)); // { dg-error "function or function type with a return type" } + } + ~S () { + int a; + constexpr auto r = return_type_of (type_of (parent_of (^^a))); // { dg-error "does not have a type" } + constexpr auto t = return_type_of (parent_of (^^a)); // { dg-error "function or function type with a return type" } + } +};