mailing list of musl libc
 help / color / mirror / code / Atom feed
From: James Y Knight <jyknight@google.com>
To: musl@lists.openwall.com
Subject: Re: [musl] add noexcept to all functions please
Date: Sun, 7 Nov 2021 12:37:09 -0500	[thread overview]
Message-ID: <CAA2zVHqHTh9OZfxPRo0XAL0npnDrMbebaYasZfMsuTArrN40eQ@mail.gmail.com> (raw)
In-Reply-To: <YYbL/2nQje5Cj7pk@wirbelwind.zhasha.com>

[-- Attachment #1: Type: text/plain, Size: 2166 bytes --]

On Sat, Nov 6, 2021 at 2:40 PM Joakim Sindholt <opensource@zhasha.com>
wrote:

> On Sat, Nov 06, 2021 at 06:28:31PM +0000, Jon Chesterfield wrote:
> > That's a compiler bug, surely. A C function that takes no callbacks is
> not
> > going to throw.
>
> I don't think the compiler can prove that. As far as I know the extern
> "C" {} that C headers get wrapped in for C++ just means the compiler
> doesn't type-mangle function names. The function itself can not only
> throw by itself but it can also call other functions that throw as part
> of its implementation.


That's correct. In general, extern "C" functions are allowed to throw.


> If there's a compiler bug here it would have to be that it discards
> knowledge about C standard functions that can indeed not throw. I don't
> know if that's the case here, or if it's just nonstandard functions that
> are affected.


Some of the common standard functions are detected and treated specially by
compilers. Such libc functions that have special-casing are already
generally treated as non-throwing by both GCC and Clang. However, there are
a _lot_ of libc functions, both standard and nonstandard, that the compiler
doesn't hardcode any knowledge about.


> FWIW I don't think musl should tag any functions with anything just to
> make C++ marginally faster. This seems like a case of C++ getting
> hoisted by its own petard.
>

I have no horse in this race, but that really seems not a very helpful
attitude. There's a large number of users of libc who are using C++ rather
than C -- and many (most?) of them are compiling with exceptions enabled.
If adding minor cruft to all of the libc function declarations will make a
meaningful difference to all of that code's performance, that seems well
worth considering, regardless of anyone's opinions regarding decisions
about how to implement exceptions in C++ that were made 30 years ago.

Glibc defines macros for this purpose, which expand into "throw()" in C++
and "__attribute__((__nothrow__))" in GCC-C. The latter is only useful in
conjunction with an extremely-rarely-used feature, C code built with
-fexceptions enabled, and is thus probably ignorable.

[-- Attachment #2: Type: text/html, Size: 2983 bytes --]

  reply	other threads:[~2021-11-07 17:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-06 17:15 sotrdg sotrdg
2021-11-06 18:28 ` Jon Chesterfield
2021-11-06 18:39   ` Joakim Sindholt
2021-11-07 17:37     ` James Y Knight [this message]
2021-11-07 18:20       ` Florian Weimer
2021-11-07 19:56         ` Markus Wichmann
2021-11-08  8:30           ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAA2zVHqHTh9OZfxPRo0XAL0npnDrMbebaYasZfMsuTArrN40eQ@mail.gmail.com \
    --to=jyknight@google.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).