[cfe-commits] [libcxxabi] r137118 - /libcxxabi/trunk/src/cxa_exception.cpp

Howard Hinnant hhinnant at apple.com
Tue Aug 9 17:34:54 PDT 2011


On Aug 9, 2011, at 8:24 PM, John McCall wrote:

> On Aug 9, 2011, at 5:11 PM, Howard Hinnant wrote:
>> On Aug 9, 2011, at 1:52 PM, John McCall wrote:
>>> On Aug 9, 2011, at 8:09 AM, Marshall Clow wrote:
>>>> +static const uint64_t kOurDependentExceptionClass = 0x434C4E47432B2B01; // CLNGC++\1
>>> 
>>> Ugh.  I would prefer to avoid Sebastian's dependent exception stuff.
>> 
>> It is coming.  I'll get it in.
>> 
>>> Is it
>>> really unreasonable to say that std::rethrow_exception can only rethrow
>>> a non-foreign exception?
>> 
>> I don't know the answer to this one.  I think we should try to keep the functionality of Apple's current abi, but deciphering exactly what that is is a non-trivial task.
> 
> Apple's current ABI does not implement std::exception_ptr, nor does it try to support any of the "dependent" exception stuff.

This test, taken from libc++/test/language.support/support.exception/propagation/rethrow_exception.cpp:

//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// <exception>

// void rethrow_exception [[noreturn]] (exception_ptr p);

#include <exception>
#include <cassert>

struct A
{
    static int constructed;
    int data_;

    A(int data = 0) : data_(data) {++constructed;}
    ~A() {--constructed;}
    A(const A& a) : data_(a.data_) {++constructed;}
};

int A::constructed = 0;

int main()
{
    {
        std::exception_ptr p;
        try
        {
            throw A(3);
        }
        catch (...)
        {
            p = std::current_exception();
        }
        try
        {
            std::rethrow_exception(p);
            assert(false);
        }
        catch (const A& a)
        {
            assert(A::constructed == 1);
            assert(p != nullptr);
            p = nullptr;
            assert(p == nullptr);
            assert(a.data_ == 3);
            assert(A::constructed == 1);
        }
        assert(A::constructed == 0);
    }
}

passes for me on Lion using clang++ -std=c++0x -stdlib=libc++.  I implemented the "dependent" exception stuff quite awhile ago (you're welcome ;-)).

> 
> As far as I understand it, Sebastian introduced dependent (i.e. wrapped) exceptions in order to support capturing and rethrowing an arbitrary, potentially foreign exception via std::exception_ptr.

In gcc, yes.  And it is that design, described at a high level in cxx-abi-dev, that I followed (the high level description in cxx-abi-dev, not the code in gcc).

>  That's the only thing I can see that warrants the added complexity.  If we throw out that requirement, then we always have a reliable reference count we can use on exception_ptrs.

std::exception_ptr is part of C++11, and part of Apple API/ABI in Lion, and going forward.  Our implementation is conforming to C++11, but very nearly wasn't due to an attempt by Microsoft and parts of Bloomberg, and initially parts of IBM to change the spec out from under us at the very last minute (in Madrid this Spring).  Doug helped me quell that last minute design change.

Howard




More information about the cfe-commits mailing list