https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126155
Bug ID: 126155
Summary: Put_Image forces a leading New_Line for composite
types
Product: gcc
Version: 16.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ada
Assignee: unassigned at gcc dot gnu.org
Reporter: mnpjm6zqj6tckbx8zscf at mailbox dot org
CC: dkm at gcc dot gnu.org
Target Milestone: ---
Created attachment 64957
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64957&action=edit
A sample program showing the discussed issue for a default and a redefined
Put_Image
GNAT prepends a New_Line by default for some composite types such as arrays,
records and Ada.Containers (through the Array_Before procedure [1]).
ARM 4.10(46/5) permits the addition of New_Lines for the sake of improved
readability [2].
However, GNAT's implementation:
1) prepends an empty line in default cases, for example when printing an array:
```text
Show_Empty_New_Line
------- Before --------
[ 1, 2, 3]
------- After ---------
```
2) prevents alignment of components in custom Put_Image that uses
Increase_Indent:
```text
Show_Misalignment
Composite
ID => "#1"
Data =>
[ 1, 2, 3]
Flag => TRUE
```
If this is purely a cosmetic choice, my suggestion would be to remove the call
to New_Line in Array_Before without qualification.
If this is related to some other case (like when a tag is prepended), my
suggestion would be to add New_Line in these specific places and remove the
New_Line as above.
[1]
https://gcc.gnu.org/cgit/gcc/tree/gcc/ada/libgnat/s-putima.adb?id=eb8ff3cbc09e029ca0cbd0d8b09bcaba162ab95a#n214
[2] https://ada-rapporteur-group.github.io/ARM/Ada_2022/RM-4-10.html