public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* An interesting thought on exception_defines.h just for fun
@ 2021-10-05 16:57 unlvsur unlvsur
  2021-10-05 17:05 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: unlvsur unlvsur @ 2021-10-05 16:57 UTC (permalink / raw)
  To: unlvsur unlvsur via Libstdc++

Is that possible to use if constexpr(true) for __try and if constexpr(false) for __catch when we compile it with C++17 and C++20 instead of If(true) and if(false) when people disable exceptions?

gcc/exception_defines.h at 16e2427f50c208dfe07d07f18009969502c25dc8 · gcc-mirror/gcc · GitHub<https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/libstdc%2B%2B-v3/libsupc%2B%2B/exception_defines.h>


Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: An interesting thought on exception_defines.h just for fun
  2021-10-05 16:57 An interesting thought on exception_defines.h just for fun unlvsur unlvsur
@ 2021-10-05 17:05 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2021-10-05 17:05 UTC (permalink / raw)
  To: unlvsur unlvsur; +Cc: unlvsur unlvsur via Libstdc++

On Tue, 5 Oct 2021 at 17:57, unlvsur unlvsur via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> Is that possible to use if constexpr(true) for __try and if constexpr(false) for __catch when we compile it with C++17 and C++20 instead of If(true) and if(false) when people disable exceptions?
>
> gcc/exception_defines.h at 16e2427f50c208dfe07d07f18009969502c25dc8 · gcc-mirror/gcc · GitHub<https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/libstdc%2B%2B-v3/libsupc%2B%2B/exception_defines.h>

Yes, that should work OK, but I don't expect it to make much
difference in practice. It might prevent some template instantiations
if something is only odr-used in a catch handler, but that wouldn't be
very common, and those instantiations would be discarded by the
compiler anyway, because the if (false) branch is never taken.

--- a/libstdc++-v3/libsupc++/exception_defines.h
+++ b/libstdc++-v3/libsupc++/exception_defines.h
@@ -32,8 +32,13 @@

#if ! __cpp_exceptions
// Iff -fno-exceptions, transform error handling code to work without it.
-# define __try      if (true)
-# define __catch(X) if (false)
+# if __cplusplus >= 201703L
+#  define __try      if constexpr (true)
+#  define __catch(X) if constexpr (false)
+# else
+#  define __try      if (true)
+#  define __catch(X) if (false)
+# endif
# define __throw_exception_again
#else
// Else proceed normally.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-05 17:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-05 16:57 An interesting thought on exception_defines.h just for fun unlvsur unlvsur
2021-10-05 17:05 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).