and FROM is the info for from(). */
static tree
-get_meta_exception_object (location_t loc, const char *what, tree from,
- bool *non_constant_p)
+get_meta_exception_object (location_t loc, const constexpr_ctx *ctx,
+ const char *what, tree from, bool *non_constant_p)
{
/* Don't throw in a template. */
- // TODO For -fno-exceptions, report an error.
if (processing_template_decl)
{
*non_constant_p = true;
return NULL_TREE;
}
+ /* Don't try to throw exceptions with -fno-exceptions. */
+ if (!flag_exceptions)
+ {
+ if (!cxx_constexpr_quiet_p (ctx))
+ {
+ auto_diagnostic_group d;
+ error_at (loc, "%qD should throw %qs; %<what()%>: %qs",
+ from, "std::meta::exception", _(what));
+ inform (loc, "exceptions are disabled, treating as non-constant");
+ }
+ *non_constant_p = true;
+ return NULL_TREE;
+ }
+
tree type = lookup_qualified_name (std_meta_node, "exception",
LOOK_want::TYPE, /*complain*/true);
if (TREE_CODE (type) != TYPE_DECL || !CLASS_TYPE_P (TREE_TYPE (type)))
throw_exception (location_t loc, const constexpr_ctx *ctx, const char *msgid,
tree from, bool *non_constant_p, tree *jump_target)
{
- if (tree obj = get_meta_exception_object (loc, msgid, from, non_constant_p))
+ if (tree obj = get_meta_exception_object (loc, ctx, msgid, from,
+ non_constant_p))
*jump_target = cxa_allocate_and_throw_exception (loc, ctx, obj);
return NULL_TREE;
}
--- /dev/null
+// PR c++/124417
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection -fno-exceptions" }
+
+#include <meta>
+
+auto a = is_enum_type (^^::);
+// { dg-error "call to consteval function 'std::meta::is_enum_type\\\(\\\^\\\^::\\\)' is not a constant expression" "" { target *-*-* } .-1 }
+// { dg-error "'consteval bool std::meta::is_enum_type\\\(info\\\)' should throw 'std::meta::exception'; 'what\\\(\\\)': 'reflection does not represent a type'" "" { target *-*-* } .-2 }
+// { dg-message "exceptions are disabled, treating as non-constant" "" { target *-*-* } .-3 }