diff --git a/gcc/testsuite/g++.dg/reflect/eh8.C b/gcc/testsuite/g++.dg/reflect/eh8.C index ac4afa4b053..183715f33f0 100644 --- a/gcc/testsuite/g++.dg/reflect/eh8.C +++ b/gcc/testsuite/g++.dg/reflect/eh8.C @@ -24,7 +24,7 @@ bar () { exception a (u8"\N{GRINNING FACE}\N{GRINNING FACE WITH SMILING EYES}\N{LEFT SPEECH BUBBLE}", ^^foo); const char *b = a.what (); // { dg-message "in 'constexpr' expansion of 'a.std::meta::exception::what\\\(\\\)" } - return true; // { dg-error "inline assembly is not a constant expression" "" { target *-*-* } 0 } + return true; // { dg-error "constexpr message: std::meta::exception message could not be successfully transcoded from UTF-8 to ordinary literal encoding" "" { target *-*-* } 0 } } static_assert (foo ()); diff --git a/gcc/testsuite/g++.dg/reflect/no-exceptions2.C b/gcc/testsuite/g++.dg/reflect/no-exceptions2.C new file mode 100644 index 00000000000..b9431e31614 --- /dev/null +++ b/gcc/testsuite/g++.dg/reflect/no-exceptions2.C @@ -0,0 +1,15 @@ +// { dg-do compile { target c++26 } } +// { dg-additional-options "-freflection -fno-exceptions" } + +#include + +consteval bool +foo () +{ + auto ctx = std::meta::access_context::unchecked (); + auto ctx2 = ctx.via (^^::); // { dg-message "in 'constexpr' expansion of 'ctx.std::meta::access_context::via\\\(\\\^\\\^::\\\)'" } + return true; +} + +auto b = foo (); // { dg-message "in 'constexpr' expansion of 'foo\\\(\\\)'" } +// { dg-error "constexpr message: std::meta::access_context::via argument other than null or complete class type reflection" "" { target *-*-* } 0 } diff --git a/libstdc++-v3/include/std/meta b/libstdc++-v3/include/std/meta index 2ed7708dcbf..d72c73894f2 100644 --- a/libstdc++-v3/include/std/meta +++ b/libstdc++-v3/include/std/meta @@ -120,7 +120,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // from UTF-8 to ordinary literal encoding failed. // In that case what() should be non-constant. if (_M_what.size() == 0 && _M_u8what.size() != 0) +#if __has_builtin(__builtin_constexpr_diag) + __builtin_constexpr_diag (2, "", + "std::meta::exception message could not " + "be successfully transcoded from UTF-8 to " + "ordinary literal encoding"); +#else __asm__(""); +#endif return _M_what.c_str(); } consteval u8string_view u8what() const noexcept { return _M_u8what; } @@ -591,15 +598,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION access_context::via(info __cls) const { if (__cls != info {} - && (!std::meta::is_class_type(__cls) + && (!std::meta::is_type(__cls) + || !std::meta::is_class_type(__cls) || !std::meta::is_complete_type(__cls))) { #if __cpp_exceptions throw std::meta::exception(u8"via argument other than null " "or complete class type reflection", ^^access_context::via); +#else +#if __has_builtin(__builtin_constexpr_diag) + __builtin_constexpr_diag (2, "", + "std::meta::access_context::via argument " + "other than null or complete class type " + "reflection"); #else __asm__(""); +#endif return *this; #endif }