From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3D7913858403; Mon, 12 Sep 2022 20:51:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D7913858403 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663015885; bh=UKurtM9iNXaONwwFkzCvZ2x6gNFfNK9vshO2Q81C0YE=; h=From:To:Subject:Date:From; b=ZQGzitoMOGjRfH4yqxcZaxxgS0tNgv1Bz0bPG0yemF0LVmGI5vzNBS7fsF4lMLdOo TtZrbk+en4cFB61IDjoV940M3PGqzQ0dFpatEDxwanyscJ9nhSSJ1BjavBtKv1fFGg A4Buq4rV6iziQMi9SaAGqw4fVxI2NNKyzYmLJlRo= From: "guez at lmd dot ens.fr" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/106918] New: Cannot use structure constructor with component allocatable character array of deferred length Date: Mon, 12 Sep 2022 20:51:25 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: guez at lmd dot ens.fr X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106918 Bug ID: 106918 Summary: Cannot use structure constructor with component allocatable character array of deferred length Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: guez at lmd dot ens.fr Target Milestone: --- gcc version 12.0.1 20220319 (experimental) [master r12-7719-g8ca61ad148f] (Ubuntu 12-20220319-1ubuntu1) Configured with: ../src/configure -v --with-pkgversion=3D'Ubuntu 12-20220319-1ubuntu1' --with-bugurl=3Dfile:///usr/share/doc/gcc-12/README.B= ugs --enable-languages=3Dc,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=3D/usr --with-gcc-major-version-only --program-suffix=3D-12 --program-prefix=3Dx86_64-linux-gnu- --enable-shared --enable-linker-build-= id --libexecdir=3D/usr/lib --without-included-gettext --enable-threads=3Dposix --libdir=3D/usr/lib --enable-nls --enable-clocale=3Dgnu --enable-libstdcxx-= debug --enable-libstdcxx-time=3Dyes --with-default-libstdcxx-abi=3Dnew --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=3Drelea= se --with-target-system-zlib=3Dauto --enable-objc-gc=3Dauto --enable-multiarch --disable-werror --enable-cet --with-arch-32=3Di686 --with-abi=3Dm64 --with-multilib-list=3Dm32,m64,mx32 --enable-multilib --with-tune=3Dgeneric --enable-offload-targets=3Dnvptx-none=3D/build/gcc-12-OcsLtf/gcc-12-12-2022= 0319/debian/tmp-nvptx/usr,amdgcn-amdhsa=3D/build/gcc-12-OcsLtf/gcc-12-12-20= 220319/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=3Drelease --build=3Dx86_64-linux-gnu --host=3Dx86_64-linux-gnu --target=3Dx86_64-linu= x-gnu GNU Fortran (Ubuntu 11.2.0-19ubuntu1) 11.2.0 Here is a test program: $ cat test_coord_def.f90 character(len =3D :), allocatable:: attr_name(:) type coord_def character(len =3D :), allocatable:: attr_name(:) end type coord_def type(coord_def) coordinates attr_name =3D ["units"] print *, 'attr_name: "', attr_name, '"' coordinates =3D coord_def(attr_name) print *, 'coordinates%attr_name: "', coordinates%attr_name, '"' end The compilation command is: $ gfortran-12 test_coord_def.f90 There is no compilation message. The execution fails: $ ./a.out attr_name: "units" Operating system error: Cannot allocate memory Memory allocation failure in xrealloc Error termination. Backtrace: #0 0x1538fa556ae0 in ??? #1 0x1538fa557659 in ??? #2 0x1538fa557834 in ??? #3 0x1538fa555fee in ??? #4 0x1538fa7ba355 in ??? #5 0x1538fa7ab1b9 in ??? #6 0x1538fa7b3c00 in ??? #7 0x1538fa7b90ae in ??? #8 0x1538fa7ba105 in ??? #9 0x1538fa7ab8a8 in ??? #10 0x555fac4a76d8 in ??? #11 0x555fac4a7751 in ??? #12 0x1538fa334d8f in __libc_start_call_main at ../sysdeps/nptl/libc_start_call_main.h:58 #13 0x1538fa334e3f in __libc_start_main_impl at ../csu/libc-start.c:392 #14 0x555fac4a7114 in ??? #15 0xffffffffffffffff in ??? I think the source code is valid. Note that if I replace the structure constructor by an equivalent assignment to the component, the problem disappears: $ cat test_coord_def.f90 character(len =3D :), allocatable:: attr_name(:) type coord_def character(len =3D :), allocatable:: attr_name(:) end type coord_def type(coord_def) coordinates attr_name =3D ["units"] print *, 'attr_name: "', attr_name, '"' coordinates%attr_name =3D attr_name !!coordinates =3D coord_def(attr_name) print *, 'coordinates%attr_name: "', coordinates%attr_name, '"' end $ gfortran-12 test_coord_def.f90 $ ./a.out attr_name: "units" coordinates%attr_name: "units" Also, for additional information, there is no problem with ifort 19.1.=