public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/49255] New: -fcheck=pointer diagnosts too much: Passing NULL pointer to OPTIONAL argument
@ 2011-06-01 13:12 burnus at gcc dot gnu.org
  2011-06-02  5:55 ` [Bug fortran/49255] -fcheck=pointer diagnoses " burnus at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-06-01 13:12 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49255

           Summary: -fcheck=pointer diagnosts too much: Passing NULL
                    pointer to OPTIONAL argument
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: diagnostic, patch, rejects-valid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org


Valid F2008 test case:

integer,pointer :: ptr => null()
call foo(ptr)
contains
  subroutine foo (x)
    integer, optional :: x
    print *, present (x)
  end subroutine foo
end


But with -fcheck=pointer, gfortran prints at run time:

At line 2 of file test.f90
Fortran runtime error: Pointer actual argument 'ptr' is not associated


--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -3269,13 +3269,16 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
          else
            goto end_pointer_check;

-          if (attr.optional)
+          if (attr.optional
+             && ((gfc_option.allow_std & GFC_STD_F2008) == 0
+                 || attr.proc_pointer))
            {
               /* If the actual argument is an optional pointer/allocatable and
                 the formal argument takes an nonpointer optional value,
                 it is invalid to pass a non-present argument on, even
                 though there is no technical reason for this in gfortran.
-                See Fortran 2003, Section 12.4.1.6 item (7)+(8).  */
+                See Fortran 2003, Section 12.4.1.6 item (7)+(8).
+                In Fortran 2008 that's allowed; cf. 12.5.2.12.  */
              tree present, null_ptr, type;

              if (attr.allocatable


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

end of thread, other threads:[~2011-06-05 21:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-01 13:12 [Bug fortran/49255] New: -fcheck=pointer diagnosts too much: Passing NULL pointer to OPTIONAL argument burnus at gcc dot gnu.org
2011-06-02  5:55 ` [Bug fortran/49255] -fcheck=pointer diagnoses " burnus at gcc dot gnu.org
2011-06-05 21:12 ` burnus at gcc dot gnu.org
2011-06-05 21:13 ` burnus 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).