https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70015
Bug ID: 70015
Summary: Finalizer not called depending on declaration order
Product: gcc
Version: 4.9.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ada
Assignee: unassigned at gcc dot gnu.org
Reporter: tjk at tksoft dot com
Target Milestone: ---
Created attachment 37823
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37823&action=edit
Example 1 where Finalizer call gets omitted
Call to the Finalizer for an object doesn't get called, or gets called twice,
unless declarations are placed in a specific order.
I wrote five versions of the same code, with two versions producing the bug;
two are workarounds which make the code useless, and the fifth example actually
makes the code work as it should.
The behavior is unpredictable and violates the expected behavior of a
controlled type, so this should probably be classified as a rather serious
issue.
The original code is for a parser, and written in a pretty predictable way, so
I wouldn't be surprised if there was other code out there where this bug just
hasn't been noticed. A missing Finalizer call will only be noticed if the
controlled resource misbehaves because of a lacking call to the finalizer.
Complete list of examples:
http://tksoft.com/people/troy/ada/dtor_examples/