Question: Why are std::exception & friends not in a versioned namespace?

The title of the message pretty much says everything. I’m wondering why `std::exception` is not `std::__1::exception` instead — most symbols are in the versioned namespace, but not this one.

Thanks,
Louis

"Magic" types that the compiler / core language know about don't go in the versioned namespace.

Thanks!

Louis

+libcxx-dev, which I accidentally dropped.

“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.)

“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.

Louis

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

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::slight_smile: 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