[llvm-bugs] [Bug 47365] Can not use a struct type of base containing both enum and protected destructor

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 31 13:51:12 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47365

Richard Smith <richard-llvm at metafoo.co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|NEW                         |RESOLVED

--- Comment #1 from Richard Smith <richard-llvm at metafoo.co.uk> ---
This is a GCC bug. The relevant language rule is [dcl.init.aggr]/8:

"""
The destructor for each element of class type is potentially invoked (11.4.6)
from the context where the aggregate initialization occurs.
"""

... and per [class.dtor]/15:

"""
A program is ill-formed if a destructor that is potentially invoked is deleted
or not accessible from the context of the invocation.
"""

To see why this rule exists, consider this variant on your testcase:

struct B {
protected:
    ~B() {}
};

struct C : B { int n; };

int f();

void g() {
    C c{{}, f()};
//    C c{B{}, f()};
}

Here, if f() throws an exception, the destructor for the temporary B object
constructed as C's base class needs to be called, but B::~B() is inaccessible
from the context of g().

If you make B's destructor public, GCC miscompiles the above testcase by
failing to destroy the B base class if the call to f() throws an exception.

If you uncomment the second line of g(), then GCC rejects the above example,
even though those two lines are equivalent.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200831/b3e0a4d0/attachment.html>


More information about the llvm-bugs mailing list