[PATCH C++] document order of C++ ctors and attribute constructor is unspecified

Martin Sebor msebor@gmail.com
Thu Mar 16 15:22:00 GMT 2017


On 03/15/2017 10:49 PM, Jason Merrill wrote:
> On Wed, Mar 15, 2017 at 6:59 PM, Martin Sebor <msebor@gmail.com> wrote:
>> In bug 52477 - Wrong initialization order?  attribute constructor
>> vs static data access, the reporter expects C++ objects with static
>> storage duration to have their ctors called in the same order as
>> those of functions declared with attribute constructor interleaved
>> with them.
>>
>> In his comment on the bug Richard opines that relying on the order
>> is undefined.  The attached patch updates the manual to make this
>> clear.
>
> I disagree with that comment, and have added one of my own, but I
> think your patch is appropriate for GCC 7 since we aren't going to fix
> it in this release.

Okay, thanks.  In that case I should probably word it slightly
differently.  I've added "at present" below to imply (hint) that
this might change in the future.  I'll go with this unless you
have a different suggestion.

However, <ins>at present, </ins>the order in which constructors
for C++ objects with static storage duration and functions decorated
with attribute @code{constructor} are invoked is unspecified.  In
mixed declarations, attribute @code{init_priority} can be used to
impose a specific ordering.

Martin



More information about the Gcc-patches mailing list