[libcxx-dev] Question: Why are std::exception & friends not in a versioned namespace?

Olivier Giroux via libcxx-dev libcxx-dev at lists.llvm.org
Wed Oct 24 10:57:36 PDT 2018


Not that it’s a priority to support this, but I did run into this as well during my freestanding prototype. I used the versioned namespace macros to inject a different namespace name (in my case simt::std::) but I couldn’t do that with those few facilities that are put into std:: literally in the implementation of libc++. I found another way to do what I wanted to do that worked because I didn’t want to hook any of those facilities, but if I wanted to do that in the future I would like to see an unversioned namespace macro even if it’s always set to std:: in normal builds of libc++.

Olivier

From: libcxx-dev <libcxx-dev-bounces at lists.llvm.org> on behalf of Marshall Clow via libcxx-dev <libcxx-dev at lists.llvm.org>
Reply-To: Marshall Clow <mclow.lists at gmail.com>
Date: Wednesday, October 24, 2018 at 10:48 AM
To: "ldionne at apple.com" <ldionne at apple.com>
Cc: "libcxx-dev at lists.llvm.org" <libcxx-dev at lists.llvm.org>
Subject: Re: [libcxx-dev] Question: Why are std::exception & friends not in a versioned namespace?

On Mon, Oct 22, 2018 at 5:58 AM Louis Dionne via libcxx-dev <libcxx-dev at lists.llvm.org<mailto:libcxx-dev at lists.llvm.org>> wrote:
On Oct 19, 2018, at 3:18 PM, Richard Smith <richard at metafoo.co.uk<mailto:richard at metafoo.co.uk>> wrote:

On Wed, 17 Oct 2018 at 11:44, Ben Craig via libcxx-dev <libcxx-dev at lists.llvm.org<mailto:libcxx-dev at lists.llvm.org>> wrote:
"Magic" types that the compiler / core language know about don't go in the versioned namespace.

That certainly applies to things like std::type_info, std::initializer_list, and std::bad_alloc, but std::exception is not special in this regard.

Rather, I think the reason we don't version std::exception is so that in code that mixes use of libc++ and libstdc++, one can throw an exception derived from std::exception using one library and catch it using the other library. (A special case of that: the default 'terminate' handler can print out details of the thrown exception if it's derived from std::exception, even if it's using the std::exception from a different stdlib.)

That makes a lot of sense. This means we have an official or unofficial "contract" with libstdc++ not to put those symbols in a versioned namespace.

Right.
We (the libc++ maintainers and the libstdc++ maintainers) agree that it would be nice to be able to mix code, and so we do this (and a couple other things) to make it so. For example, the libc++ exception classes look weird, but that's so they work like the libstdc++ ones.

-- Marshall

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/libcxx-dev/attachments/20181024/f30483dc/attachment.html>


More information about the libcxx-dev mailing list