]> git.ipfire.org Git - thirdparty/gcc.git/commit
Ada: Fix variable initialized with if-expression not flagged as constant
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 12 Nov 2025 08:03:18 +0000 (09:03 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Wed, 12 Nov 2025 08:05:39 +0000 (09:05 +0100)
commitb0e56bc6ad9fc54841070d676bc2bd9b5e2f8b6d
tree125782cbd5a97c0463b37baed959d78205277c6d
parenteeccfad6a6352fb7a39b359fe7b569717f735cce
Ada: Fix variable initialized with if-expression not flagged as constant

This is a regression present on the mainline and 15 branch: the -gnatwk
switch no longer flags a string variable initialized with an if-expression
as constant when it is not modified in the program.  The fix is to set the
Has_Initial_Value and Never_Set_In_Source flags earlier during analysis in
the Analyze_Object_Declaration procedure.

gcc/ada/
PR ada/122640
* sem_ch3.adb (Analyze_Object_Declaration): Set Is_True_Constant
on entry for constants and Never_Set_In_Source in all cases.
If an initialization expression is present, set Has_Initial_Value
and Is_True_Constant on variables.

gcc/testsuite/
* gnat.dg/warn34.adb: New test.
gcc/ada/sem_ch3.adb
gcc/testsuite/gnat.dg/warn34.adb [new file with mode: 0644]