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: unassig...@gcc.gnu.org
        ReportedBy: bur...@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

Reply via email to