Bug 40678 - Using a function as variable: ICE with 4.3, accepts invalid with 4.4/4.5
Summary: Using a function as variable: ICE with 4.3, accepts invalid with 4.4/4.5
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2009-07-07 22:56 UTC by Thomas Orgis
Modified: 2019-01-23 06:56 UTC (History)
2 users (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-07-08 07:36:28


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Orgis 2009-07-07 22:56:33 UTC
Gfortran does not like me forgetting () on function calls.
Simple test code:

module ice

implicit none


contains

subroutine in_the
	logical :: there_is

	there_is = sunshine ! () are missing!
end subroutine

function sunshine()
	logical :: sunshine

	sunshine = .true.
end function

end module


$ LANG=C gfortran -c -o gccice.o gccice.f90 
gccice.f90: In function 'in_the':
gccice.f90:17: internal compiler error: in gfc_conv_variable, at fortran/trans-expr.c:483
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 Tobias Burnus 2009-07-08 07:36:28 UTC
I can reproduce the ICE with 4.1, 4.2 and 4.3 - but it no longer gives an ICE with 4.4 or 4.5.

 * * *

However, there is also a bug in 4.4: It simply compiles.


Expected: Either an error of the form (NAG f95)

Error: aa.f90, line 6: Implicit type for SUNSHINE
       detected at SUNSHINE@<end-of-statement>

or -- better (or additionally) -- of the form

error #6423: This name has already been used as an external function name.   [SUNSHINE]

 * * *

In 4.3.4 the following assert fails:
      /* Procedure actual arguments.  */
      else if (sym->attr.flavor == FL_PROCEDURE
               && se->expr != current_function_decl)
        {
          gcc_assert (se->want_pointer);
Comment 2 Tobias Burnus 2009-07-09 14:48:00 UTC
> However, there is also a bug in 4.4: It simply compiles.
But if one adds a "print *, there_is", one sees that it does not work (wrong result, independent of sunshine()!)
Comment 3 janus 2011-11-03 07:07:34 UTC
The program is still accepted without error with 4.6 and 4.7 trunk.

However,

print *,sunshine

triggers the expected error:

  print *,sunshine
                  1
Error: Function 'sunshine' requires an argument list at (1)
Comment 4 G. Steinmetz 2018-10-23 16:51:36 UTC
No ICE with versions configured with --enable-checking=yes or =release.


$ cat z1.f90
module m
   implicit none
contains
   subroutine s
      logical :: f
      f = g !()
   end
   logical function g()
      g = .true.
   end
end


$ gfortran-9-20181021-chk -c z1.f90
Comment 5 G. Steinmetz 2018-10-23 16:52:57 UTC

Following program compiles smoothly and runs ...
Invocations of function h need obligatoric parenthesis, and a dummy.
On the other hand, "implicit none" would force variable h to be
explicitly declared.


$ cat z2.f90
module m
   implicit none
contains
   logical function f()
      f = h
   end function
   logical function g()
      g = .not. h
   end function
   logical function h(x)
      logical, intent(in) :: x
      h = .not. x
   end function
end
program p
   use m
   print *, f()
   print *, g()  ! .not. f()
end


$ gfortran-9-20181021-chk -Wall -Wextra -fcheck=all -static-libgfortran -g z2.f90
$ a.out
 F
 F