Tweak what() for return_type_of

This commit is contained in:
Marek Polacek
2026-01-09 12:42:25 -05:00
parent 1921bd08d7
commit e1768101d0
2 changed files with 23 additions and 1 deletions

View File

@@ -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)

View File

@@ -0,0 +1,20 @@
// { dg-do compile { target c++26 } }
// { dg-additional-options "-freflection" }
// Test std::meta::return_type_of.
#include <meta>
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" }
}
};