public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/97612] New: Structure constructor of type with nested allocatable array components fails to compile
@ 2020-10-28  8:51 mscfd at gmx dot net
  2020-12-02 20:15 ` [Bug fortran/97612] " dominiq at lps dot ens.fr
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: mscfd at gmx dot net @ 2020-10-28  8:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97612

            Bug ID: 97612
           Summary: Structure constructor of type with nested allocatable
                    array components fails to compile
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mscfd at gmx dot net
  Target Milestone: ---

The program below does not compile with error message:

constructor_allocatable.F90:4:9:

    4 | type :: s
      |         1
Error: The rank of the element in the structure constructor at (1) does not
match that of the component (0/1)

It is essential that x is an array, and that component u of type s has the
allocatable attribute as well. However, component u does not need to be an
array to trigger the error.


program constructor_allocatable
implicit none

type :: s
   integer, dimension(:), allocatable :: u
end type s

type :: t
   type(s), dimension(:), allocatable :: x
end type t

type(t) :: a = t()

end program constructor_allocatable

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/97612] Structure constructor of type with nested allocatable array components fails to compile
  2020-10-28  8:51 [Bug fortran/97612] New: Structure constructor of type with nested allocatable array components fails to compile mscfd at gmx dot net
@ 2020-12-02 20:15 ` dominiq at lps dot ens.fr
  2020-12-07  9:23 ` mscfd at gmx dot net
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dominiq at lps dot ens.fr @ 2020-12-02 20:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97612

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2020-12-02
     Ever confirmed|0                           |1

--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Is the test valid?
What is t() supposed to do?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/97612] Structure constructor of type with nested allocatable array components fails to compile
  2020-10-28  8:51 [Bug fortran/97612] New: Structure constructor of type with nested allocatable array components fails to compile mscfd at gmx dot net
  2020-12-02 20:15 ` [Bug fortran/97612] " dominiq at lps dot ens.fr
@ 2020-12-07  9:23 ` mscfd at gmx dot net
  2020-12-07 12:46 ` [Bug fortran/97612] [F08] " dominiq at lps dot ens.fr
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mscfd at gmx dot net @ 2020-12-07  9:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97612

--- Comment #2 from martin <mscfd at gmx dot net> ---
I do not see why it should not be valid.
t() is a structure constructor acting much like a function with (in this case)
one optional argument. And as an allocatable component has default
initialisation, no value needs to be provided, to be valid constructor.

Just to be sure I checked Metcalf (2011). Section 15.3 "Structure constructors"
and 20.1.4 "Structure constructors" contain an interesting piece of information
I did not know about: F03 forgot to allow that for allocatable components a
value can be omitted. This was permitted in F08. So it looks like the provided
code example is not valid F03 but valid F08.

In fact, null() can be provided as default value. Then the code compiles:

type(t) :: a = t(null())

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/97612] [F08] Structure constructor of type with nested allocatable array components fails to compile
  2020-10-28  8:51 [Bug fortran/97612] New: Structure constructor of type with nested allocatable array components fails to compile mscfd at gmx dot net
  2020-12-02 20:15 ` [Bug fortran/97612] " dominiq at lps dot ens.fr
  2020-12-07  9:23 ` mscfd at gmx dot net
@ 2020-12-07 12:46 ` dominiq at lps dot ens.fr
  2020-12-18 12:20 ` pault at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dominiq at lps dot ens.fr @ 2020-12-07 12:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97612

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P4
             Status|WAITING                     |NEW
            Summary|Structure constructor of    |[F08] Structure constructor
                   |type with nested            |of type with nested
                   |allocatable array           |allocatable array
                   |components fails to compile |components fails to compile

--- Comment #3 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
> So it looks like the provided code example is not valid F03 but valid F08.

So my question was not totally stupid!

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/97612] [F08] Structure constructor of type with nested allocatable array components fails to compile
  2020-10-28  8:51 [Bug fortran/97612] New: Structure constructor of type with nested allocatable array components fails to compile mscfd at gmx dot net
                   ` (2 preceding siblings ...)
  2020-12-07 12:46 ` [Bug fortran/97612] [F08] " dominiq at lps dot ens.fr
@ 2020-12-18 12:20 ` pault at gcc dot gnu.org
  2020-12-29 17:50 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pault at gcc dot gnu.org @ 2020-12-18 12:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97612

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |pault at gcc dot gnu.org
                 CC|                            |pault at gcc dot gnu.org

--- Comment #4 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 49794
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49794&action=edit
Fix for the PR

This fixes the PR by effectively changing a=t() to a=t(NULL()). It even
regtests!

I need to check that this is correct when a default initializer is present for
scalar, allocatable components.

Watch this space!

Paul

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/97612] [F08] Structure constructor of type with nested allocatable array components fails to compile
  2020-10-28  8:51 [Bug fortran/97612] New: Structure constructor of type with nested allocatable array components fails to compile mscfd at gmx dot net
                   ` (3 preceding siblings ...)
  2020-12-18 12:20 ` pault at gcc dot gnu.org
@ 2020-12-29 17:50 ` cvs-commit at gcc dot gnu.org
  2021-05-04 12:31 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-29 17:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97612

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Paul Thomas <pault@gcc.gnu.org>:

https://gcc.gnu.org/g:eeb145317b42d5203056851435457d9189a7303d

commit r11-6365-geeb145317b42d5203056851435457d9189a7303d
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Tue Dec 29 17:44:48 2020 +0000

    Fortran: Correct missing structure constructor comps. [PR97612].

    2020-12-29  Paul Thomas  <pault@gcc.gnu.org>

    gcc/fortran
            PR fortran/97612
            * primary.c (build_actual_constructor): Missing allocatable
            components are set unallocated using EXPR_NULL. Then missing
            components are tested for a default initializer.

    gcc/testsuite/
            PR fortran/97612
            * gfortran.dg/structure_constructor_17.f90: New test.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/97612] [F08] Structure constructor of type with nested allocatable array components fails to compile
  2020-10-28  8:51 [Bug fortran/97612] New: Structure constructor of type with nested allocatable array components fails to compile mscfd at gmx dot net
                   ` (4 preceding siblings ...)
  2020-12-29 17:50 ` cvs-commit at gcc dot gnu.org
@ 2021-05-04 12:31 ` rguenth at gcc dot gnu.org
  2021-09-10 20:49 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-05-04 12:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97612

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/97612] [F08] Structure constructor of type with nested allocatable array components fails to compile
  2020-10-28  8:51 [Bug fortran/97612] New: Structure constructor of type with nested allocatable array components fails to compile mscfd at gmx dot net
                   ` (5 preceding siblings ...)
  2021-05-04 12:31 ` rguenth at gcc dot gnu.org
@ 2021-09-10 20:49 ` cvs-commit at gcc dot gnu.org
  2021-09-10 20:50 ` cvs-commit at gcc dot gnu.org
  2021-09-10 20:52 ` anlauf at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-10 20:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97612

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:80b1492b2de153f4850a32cafcd8f4d37c2c84fc

commit r10-10111-g80b1492b2de153f4850a32cafcd8f4d37c2c84fc
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Tue Dec 29 17:44:48 2020 +0000

    Fortran: Correct missing structure constructor comps. [PR97612].

    2020-12-29  Paul Thomas  <pault@gcc.gnu.org>

    gcc/fortran
            PR fortran/97612
            * primary.c (build_actual_constructor): Missing allocatable
            components are set unallocated using EXPR_NULL. Then missing
            components are tested for a default initializer.

    gcc/testsuite/
            PR fortran/97612
            * gfortran.dg/structure_constructor_17.f90: New test.

    (cherry picked from commit eeb145317b42d5203056851435457d9189a7303d)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/97612] [F08] Structure constructor of type with nested allocatable array components fails to compile
  2020-10-28  8:51 [Bug fortran/97612] New: Structure constructor of type with nested allocatable array components fails to compile mscfd at gmx dot net
                   ` (6 preceding siblings ...)
  2021-09-10 20:49 ` cvs-commit at gcc dot gnu.org
@ 2021-09-10 20:50 ` cvs-commit at gcc dot gnu.org
  2021-09-10 20:52 ` anlauf at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-10 20:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97612

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:19f2f22d59f4a3a7e246d09be11a727cffb8badc

commit r9-9722-g19f2f22d59f4a3a7e246d09be11a727cffb8badc
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Tue Dec 29 17:44:48 2020 +0000

    Fortran: Correct missing structure constructor comps. [PR97612].

    2020-12-29  Paul Thomas  <pault@gcc.gnu.org>

    gcc/fortran
            PR fortran/97612
            * primary.c (build_actual_constructor): Missing allocatable
            components are set unallocated using EXPR_NULL. Then missing
            components are tested for a default initializer.

    gcc/testsuite/
            PR fortran/97612
            * gfortran.dg/structure_constructor_17.f90: New test.

    (cherry picked from commit eeb145317b42d5203056851435457d9189a7303d)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug fortran/97612] [F08] Structure constructor of type with nested allocatable array components fails to compile
  2020-10-28  8:51 [Bug fortran/97612] New: Structure constructor of type with nested allocatable array components fails to compile mscfd at gmx dot net
                   ` (7 preceding siblings ...)
  2021-09-10 20:50 ` cvs-commit at gcc dot gnu.org
@ 2021-09-10 20:52 ` anlauf at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-09-10 20:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97612

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
                 CC|                            |anlauf at gcc dot gnu.org
             Status|ASSIGNED                    |RESOLVED

--- Comment #8 from anlauf at gcc dot gnu.org ---
Backported to remaining open branches after verifying that it works.  Closing.

Thanks to all!

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-09-10 20:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-28  8:51 [Bug fortran/97612] New: Structure constructor of type with nested allocatable array components fails to compile mscfd at gmx dot net
2020-12-02 20:15 ` [Bug fortran/97612] " dominiq at lps dot ens.fr
2020-12-07  9:23 ` mscfd at gmx dot net
2020-12-07 12:46 ` [Bug fortran/97612] [F08] " dominiq at lps dot ens.fr
2020-12-18 12:20 ` pault at gcc dot gnu.org
2020-12-29 17:50 ` cvs-commit at gcc dot gnu.org
2021-05-04 12:31 ` rguenth at gcc dot gnu.org
2021-09-10 20:49 ` cvs-commit at gcc dot gnu.org
2021-09-10 20:50 ` cvs-commit at gcc dot gnu.org
2021-09-10 20:52 ` anlauf at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).