https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111945
Bug ID: 111945 Summary: Attribute Image for Unbounded_String raises UTF_ENCODING.ENCODING_ERROR Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ada Assignee: unassigned at gcc dot gnu.org Reporter: alexandre.dauquier at gmail dot com CC: dkm at gcc dot gnu.org Target Milestone: --- Created attachment 56181 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56181&action=edit Minimum working example The following code is failing with Gnat 12.2.0. It passes with 13.2.0 though (so it might already be known ? But I have not found it). Note, I have picked Characters.Latin_1.Reserved_128 on purpose. ```ada -- File 'print_non_graphic_character.adb' with Ada.Characters.Latin_1; with Ada.Text_IO; with Ada.Strings.Unbounded; procedure Print_Non_Graphic_Character is Text_String : constant String := "Non Graphic Character: " & Ada.Characters.Latin_1.Reserved_128; Text_Unbounded_String : constant Ada.Strings.Unbounded.Unbounded_String := Ada.Strings.Unbounded.To_Unbounded_String (Text_String); begin Ada.Text_IO.Put_Line (Text_String); Ada.Text_IO.Put_Line (Ada.Strings.Unbounded.To_String (Text_Unbounded_String)); Ada.Text_IO.Put_Line (Text_Unbounded_String'Image); end Print_Non_Graphic_Character; ``` Note that it also fails with: ```ada Ada.Text_IO.Put_Line (Ada.Strings.Unbounded.Unbounded_String'Image (Text_Unbounded_String)); ``` ``` -- File 'print_non_graphic_character.gpr' project Print_Non_Graphic_Character is for Main use ("print_non_graphic_character.adb"); for Object_Dir use ".objs"; package Compiler is -- "-Og" -- Optimize for debug -- "-g" -- Generate debug info for Default_Switches ("Ada") use ("-g", "-gnat2020", "-Og"); end Compiler; package Binder is for Switches ("Ada") use ("-Es"); -- Symbolic traceback end Binder; end Print_Non_Graphic_Character; ``` Cmdline: `gprbuild -p -gnatef print_non_graphic_character.gpr` Output: ```stdout Non Graphic Character: � Non Graphic Character: � raised ADA.STRINGS.UTF_ENCODING.ENCODING_ERROR : bad input at Item (25) [./non_graphic_character/.objs/print_non_graphic_character] 0x40e8fb Ada.Strings.Utf_Encoding.Raise_Encoding_Error at a-stuten.adb:126 0x40f38b Ada.Strings.Utf_Encoding.Strings.Decode at a-suenst.adb:163 0x4049a8 Print_Non_Graphic_Character at print_non_graphic_character.adb:13 0x404efa Main at b__print_non_graphic_character.adb:279 [/lib/x86_64-linux-gnu/libc.so.6] 0x7f5e62118d08 [./non_graphic_character/.objs/print_non_graphic_character] 0x404658 _start at ??? 0xfffffffffffffffe ``` Output with Gnat 13.2.0 (though I didn't expect the quotation marks): ```stdout Non Graphic Character: � Non Graphic Character: � "Non Graphic Character: �" "Non Graphic Character: �" ``` Environnement of the bug (with Gnat 12.2.0): ``` > gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/home/dalex78/bin/gnat_native/12.2.1_11f3b811/bin/../libexec/gcc/x86_64-pc-linux-gnu/12.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../src/configure --prefix=/home/runner/work/GNAT-FSF-builds/GNAT-FSF-builds/sbx/x86_64-linux/gcc/install --with-build-time-tools=/home/runner/work/GNAT-FSF-builds/GNAT-FSF-builds/sbx/x86_64-linux/binutils/install/bin --enable-languages=c,ada,c++ --enable-libstdcxx --enable-libstdcxx-threads --enable-libada --disable-nls --without-libiconv-prefix --disable-libstdcxx-pch --enable-lto --disable-multilib --enable-threads=posix --with-gnu-ld --with-gnu-as --with-mpfr=/home/runner/work/GNAT-FSF-builds/GNAT-FSF-builds/sbx/x86_64-linux/mpfr/install --with-gmp=/home/runner/work/GNAT-FSF-builds/GNAT-FSF-builds/sbx/x86_64-linux/gmp/install --with-mpc=/home/runner/work/GNAT-FSF-builds/GNAT-FSF-builds/sbx/x86_64-linux/mpc/install --with-isl=/home/runner/work/GNAT-FSF-builds/GNAT-FSF-builds/sbx/x86_64-linux/isl/install --build=x86_64-pc-linux-gnu Thread model: posix Supported LTO compression algorithms: zlib gcc version 12.2.0 (GCC) ```