public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "anlauf at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/98454] Apparent wrong initialization in function result
Date: Sun, 27 Dec 2020 21:25:20 +0000	[thread overview]
Message-ID: <bug-98454-4-EIK6LsgfmW@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-98454-4@http.gcc.gnu.org/bugzilla/>

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-12-27
                 CC|                            |anlauf at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #2 from anlauf at gcc dot gnu.org ---
I think there already exists at least one PR with issues with initializers.

A reduced testcase shows that default initialization works for intent(out),
whereas you get random junk for function results.

module m_test
  implicit none
  type t
    integer :: unit = -1
  end type t
  interface test
     module procedure test_fun
  end interface
contains
  function test_fun() result(res)
    type(t) :: res
!    res = t()                     ! <-- workaround
  end function test_fun
  subroutine test_sub (res)
    type(t), intent(out) :: res
  end subroutine test_sub
end module m_test
program p
  use m_test
  implicit none
  type(t) :: x
  write(6,*) 'Before constructor'
  write(6,*) '  unit      = ', x%unit
  x = test()
  write(6,*) 'After constructor (test_fun)'
  write(6,*) '  unit      = ', x%unit
  call test_sub (x)
  write(6,*) 'After test_sub'
  write(6,*) '  unit      = ', x%unit
end program p

If you need a workaround, uncomment the indicated line.

  parent reply	other threads:[~2020-12-27 21:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-27 13:28 [Bug fortran/98454] New: " fmartinez at gmv dot com
2020-12-27 19:54 ` [Bug fortran/98454] " kargl at gcc dot gnu.org
2020-12-27 21:25 ` anlauf at gcc dot gnu.org [this message]
2020-12-27 21:44 ` anlauf at gcc dot gnu.org
2020-12-27 21:59 ` kargl at gcc dot gnu.org
2020-12-27 22:01 ` anlauf at gcc dot gnu.org
2020-12-27 22:15 ` ffadrique at gmail dot com
2020-12-27 22:18 ` ffadrique at gmail dot com
2020-12-27 23:07 ` sgk at troutmask dot apl.washington.edu
2020-12-28  8:46 ` mscfd at gmx dot net
2020-12-28  9:47 ` anlauf at gcc dot gnu.org
2020-12-28 15:19 ` anlauf at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-98454-4-EIK6LsgfmW@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).