https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122160
Bug ID: 122160
Summary: String concatenation: Ada RM 4.5.3(5) not followed
Product: gcc
Version: 15.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ada
Assignee: unassigned at gcc dot gnu.org
Reporter: [email protected]
CC: dkm at gcc dot gnu.org
Target Milestone: ---
This is an old report from 20 May 2021 [U520-036 public].
The citation from the RM is quite unmistakable IMHO.
Since it was a public report, I never got an answer. Why does GNAT fail?
=========================================================================
with Ada.Text_IO;
procedure Concat is
T: String := "" & (9 .. 16 => '0');
-- RM 4.5.3(5) ... If the left operand is a null array,
-- the result of the concatenation is the right operand.
-- The "Otherwise, the lower bound..." and (6..8) are irrelevant,
-- since the result is already defined.
E: String := (-5 .. -10 => '&');
S: String := E & (19 .. 26 => '0');
procedure Bug (X: in String) is
begin
Ada.Text_IO.Put_Line (X'First'Image & X'Last'image);
end Bug;
begin
Ada.Text_IO.Put_Line (T'First'Image & T'Last'image); -- Expected: 9 .. 16;
Result: 1 .. 8
Bug ("" & (9 .. 16 => '0')); -- Expected: 9 .. 16; Result: 1 .. 8
Ada.Text_IO.Put_Line (S'First'Image & S'Last'image); -- Expected: 19 .. 26;
Result: 1 .. 8
Bug (E & (19 .. 26 => '0')); -- Expected: 19 .. 26; Result: 1 .. 8
end Concat;
=========================================================================
Betreff: Re: [U520-036 public] - GNAT CE 2020 - Concatenation with null array
Datum: Thu, 20 May 2021 10:12:17 -0700
Von: Joel Brobecker <[email protected]>
An: Christoph & Ursula Grein <[email protected]>
Kopie (CC): [email protected]
Hello,
On Thu, May 20, 2021 at 06:48:15PM +0200, Christoph & Ursula Grein wrote:
> The program below shows that GNAT is in error here. And presumably has
> always been so.
>
> with Ada.Text_IO;
>
> procedure Concat is
>
> T: String := "" & (9 .. 16 => '0');
> -- RM 4.5.3(5) ... If the left operand is a null array,
> -- the result of the concatenation is the right operand.
> -- The "Otherwise, the lower bound..." and (6..8) are irrelevant,
> -- since the result is already defined.
>
> begin
>
> Ada.Text_IO.Put_line (T'First'Image & T'Last'image); -- Expected: 9 ..
> 16; Result: 1 .. 8
>
> end Concat;
Thank you for having taken the time to report this. We will look into it
when we have a moment.
=========================================================================
Betreff: GNAT CE 2020 - Concatenation with null array
Datum: Thu, 20 May 2021 18:48:15 +0200
Von: Christoph & Ursula Grein <[email protected]>
An: [email protected]
The program below shows that GNAT is in error here. And presumably has always
been so.
with Ada.Text_IO;
procedure Concat is
T: String := "" & (9 .. 16 => '0');
-- RM 4.5.3(5) ... If the left operand is a null array,
-- the result of the concatenation is the right operand.
-- The "Otherwise, the lower bound..." and (6..8) are irrelevant,
-- since the result is already defined.
begin
Ada.Text_IO.Put_line (T'First'Image & T'Last'image); -- Expected: 9 .. 16;
Result: 1 .. 8
end Concat;