]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Emit error if not quiet and set *non_constant_p for -fno-exceptions metafn error...
authorJakub Jelinek <jakub@redhat.com>
Wed, 11 Mar 2026 06:54:36 +0000 (07:54 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 11 Mar 2026 06:54:36 +0000 (07:54 +0100)
commitf233f787c2cef68282976cc6a507eba4e62827cb
tree52d67ef97fc7f780965b82b6f9cc66b61ad63374
parenteb908945226a63acfd215dac11b7f686f769636d
c++: Emit error if not quiet and set *non_constant_p for -fno-exceptions metafn error cases [PR124417]

For -fno-exceptions, we reject throw statements in the source, and a lot
of code in the header has #ifdef __cpp_exceptions guarded stuff and the
FE for !flag_exceptions doesn't emit some parts of the IL needed for
exceptions.  For the errors in metafns, we had just a todo to handle it
in the source but no actual implementation, so we allowed throwing
an exception and sometimes it worked to some extent and sometimes
it didn't.

The following patch fixes it by not throwing an exception if user
asked for -fno-exceptions - instead we just emit an error including
the planned what () (unless ctx->quiet) and make the evaluation
non-constant.

2026-03-11  Jakub Jelinek  <jakub@redhat.com>

PR c++/124417
* reflect.cc (get_meta_exception_object): Add CTX argument.  For
!flag_exceptions emit error unless ctx->quiet, set *non_constant_p
to true and return NULL_TREE instead of throwing an exception.
(throw_exception): Adjust get_meta_exception_object caller.

* g++.dg/reflect/no-exceptions1.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/reflect.cc
gcc/testsuite/g++.dg/reflect/no-exceptions1.C [new file with mode: 0644]