]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Fix Initialize aspect for constructors
authorDenis Mazzucato <mazzucato@adacore.com>
Fri, 9 Jan 2026 15:04:57 +0000 (16:04 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 25 May 2026 08:28:10 +0000 (10:28 +0200)
commit190643888694dae2ed35bf2b24d8f4646f1ec228
treed109fa61d6fb086c1c3740f11617925afdb514b1
parent5745b0e3c4d1470b16b8dfcb956b9320eed886ff
ada: Fix Initialize aspect for constructors

This patch improve the analysis for the Initialize aspect in constructor bodies.
Specifically:
- Assignments based on the Initialize aspect are always placed at the end of the
  constructor prologue, otherwise they could be overwritten depending on the
  original order of components.
- Introduce the "others" default choice for the Initialize aggregate.
- Improve diagnostics when the Initialize aspect is clearly misspelled.
- Flag components that are required to be initialized but are missing from the
  Initialize aspect.
- Check whether aggregate choices refer to ancestors, which is not allowed.

gcc/ada/ChangeLog:

* exp_ch3.adb (Build_Implicit_Parameterless_Constructor): Add Initialize
aspect with default others to trigger Initialize aspect analysis.
* exp_ch6.adb (Prepend_Constructor_Procedure_Prologue): Fix
initialization order.
(Init_From_Initialize_Expression): Retrieve initialization expression or
the default one base on the Initialize aspect.
(Init_From_Default_Or_Constructor):. Retrieve initialization expression
based on the default one in the record initialization list or the init
procedure.
* sem_ch13.adb (Analyze_Aspect_Specifications): Add check for
missing components that require initialization, and add an
expression_with_action node to place ABE during resolution of
aggregates with function calls.
(Check_Constructor_Choices): Helper to check that the aggregate choices
do not refer to ancestors.
(Diagnose_Misplaced_Aspects): Improve diagnostics when it is a clear
misspelling of Initialize aspect.
* sem_ch6.adb (Analyze_Direct_Attribute_Definition): If missing, add a
compiler generated Initialize aspect with default others to trigger
Initialize analysis.
gcc/ada/exp_ch3.adb
gcc/ada/exp_ch6.adb
gcc/ada/sem_ch13.adb
gcc/ada/sem_ch6.adb