]> git.ipfire.org Git - thirdparty/gcc.git/commit
Ada: Fix wrong Accum_Type inferred for a reduction expression
authorEric Botcazou <ebotcazou@adacore.com>
Sun, 7 Dec 2025 22:40:25 +0000 (23:40 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Sun, 7 Dec 2025 22:42:49 +0000 (23:42 +0100)
commit09da4112cbb38de230973ea8296816371ecb38b4
treeec68585fa5c8d390a49239eb2ef6bc075e70cce0
parent01d4414e3ea4090bffe644c9e2d2834f451ee6a5
Ada: Fix wrong Accum_Type inferred for a reduction expression

This was reported as a regression in GCC 14: the compiler resolves
Accum_Type to Positive for a reduction expression whose "expected
subtype" is Positive, which means that 0 cannot be used as initial
value in the expression:

  Sum : Positive := V'Reduce ("+", 0);

without always raising Constraint_Error as run time.  That's not the
intent according to T. Taft in
  https://forum.ada-lang.io/t/regression-in-gnat-14/890
so this changes the resolution to use the base type (Integer) instead.

gcc/ada/
PR ada/115349
* sem_attr.adb (Resolve_Attribute) <Attribute_Reduce>: Use the base
type as Accum_Type if the reducer is an operator from Standard and
the type is numeric.  Use the type of the first operand for other
operators.  Streamline the error message given for limited types.

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