[LLVMbugs] [Bug 14141] New: implicit exception spec for defaulted destructors is incorrect

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Oct 21 14:04:12 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=14141

             Bug #: 14141
           Summary: implicit exception spec for defaulted destructors is
                    incorrect
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++11
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: hhinnant at apple.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


struct B
{
    ~B() noexcept(false);
};

class A
{
   B b_;
public:
    ~A() noexcept(false) = default;
};

test.cpp:10:5: error: exception specification of explicitly defaulted
destructor does not match the calculated one
    ~A() noexcept(false) = default;
    ^
1 error generated.

The above should compile because the calculated exception spec for ~A() should
be noexcept(false).

12.4 [class.dtor]/p3:

A declaration of a destructor that does not have an exception-specification is
implicitly considered to have the same exception-specification as an implicit
declaration (15.4).

So the calculated exception spec for ~A() should be the same exception spec as
specified in 15.4 for implicit special members.

15.4 [except.spec]/p14:

An inheriting constructor (12.9) and an implicitly declared special member
function (Clause 12) have an
exception-specification. If f is an inheriting constructor or an implicitly
declared default constructor, copy constructor, move constructor, destructor,
copy assignment operator, or move assignment operator, its implicit
exception-specification specifies the type-id T if and only if T is allowed by
the exception-specification of a function directly invoked by f’s implicit
definition; f allows all exceptions if any function it directly invokes allows
all exceptions, and f has the exception-specification noexcept(true) if every
function it directly invokes allows no exceptions.

Note that in the above paragraph, the exception spec is not special for
destructors, it is handled precisely the same as for any other special member. 
that being said, overall, the exception spec for destructors *is* special.  The
difference is back in 12.4 [class.dtor]/p3.  Unlike every other special member,
not applying an exception spec doesn't mean "can throw anything."  But it also
doesn't mean "can't throw anything."  It means "can throw whatever an
implicitly defaulted destructor would throw."  This effectively means that the
implicitly generated exception spec must form an implicitly generated
destructor and create the exception spec based on what that implicitly
generated destructor would call.

In my example the implicitly generated ~A() would call ~B() which is
noexcept(false).  Therefore the implicit (calculated) exception spec for ~A()
should be noexcept(false).

Reference:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3204.htm

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list