Bug 27586 - Compile-time warn if arguments don't match in terms of precision
Summary: Compile-time warn if arguments don't match in terms of precision
Status: RESOLVED DUPLICATE of bug 26227
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.2.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-13 13:39 UTC by tobias.burnus
Modified: 2006-05-13 23:05 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tobias.burnus 2006-05-13 13:39:30 UTC
The following test case uses single precision arguments to a double precision function.

Expected: Warn during compiling
Actual: No warning is given. ./a.out shows:
  0.000000      3.0132665E+23  ! initialized with 2 & sqrt(2)

In order to make it work across files, the .mod file should contain such information (and it should be used).


From http://www.polyhedron.com/pb05/linux/diagnose.html

For the following file gfortran should issue a warning as x,y are once real and once double precision.
---<ARG1.F>--------------------
! argument mismatch - same file
      program arg1
      call sub(x,y)
      print * , x,y
      end
      subroutine sub(x,y)
      double precision x,y
      x = 2.0
      y = sqrt(x)
      end
----------------------------

gfortran-4.2 -Wall -pedantic -fbounds-check ARG1.F
produces no warning


Whereas

ifort64-9.1 -C -check all -warn all,nodec,interfaces -gen_interfaces -traceback -fpe0 -fpstkchk ARG1.F
fortcom: Error: ARG1.F, line 3: The type of the actual argument differs from the type of the dummy argument.   [X]
      call sub(x,y)
---------------^
fortcom: Error: ARG1.F, line 3: The type of the actual argument differs from the type of the dummy argument.   [Y]
      call sub(x,y)
-----------------^


g95 -Wall -pedantic -fbounds-check -ftrace=full ARG1.F
In file ARG1.F:3
      call sub(x,y)
                1
In file ARG1.F:6
      subroutine sub(x,y)
                      2
Warning (155): Inconsistent types (REAL(4)/REAL(8)) in actual argument lists at (1) and (2)

NAG: f95 -C=all -C=undefined -info -g -gline ARG1.F
Error: /tmp/ARG1.020753.f: Argument X (no. 1) in reference to SUB from ARG1 has the wrong data type
Error: /tmp/ARG1.020753.f: Argument Y (no. 2) in reference to SUB from ARG1 has the wrong data type


A meaner test is the following:
---<ARG2A.F>-------------------
!  argument mismatch - different file
      program arg2
      call sub(x,y)
      print * , x,y
      end
-------------------------------
---<ARG2B.F>-------------------
!  argument mismatch - different file
      subroutine sub(x,y)
      double precision x,y
      x = 2.0
      y = sqrt(x)
      end
-------------------------------

gfortran does not catch the problem either, of g95, ifort and NAGf95 only the Intel compiler catches this - when compiling ARG2B.F ARG2A.F. (ARG2A.F ARG2B.F no compiler catches.)

Actually, none of the compilers catches this at run time either.

ifort64-9.1 -C -check all -warn all,nodec,interfaces -gen_interfaces -traceback -fpe0 -fpstkchk ARG2B.F ARG2A.F
fortcom: Error: ARG2A.F, line 3: The type of the actual argument differs from the type of the dummy argument.   [X]
      call sub(x,y)
---------------^
fortcom: Error: ARG2A.F, line 3: The type of the actual argument differs from the type of the dummy argument.   [Y]
      call sub(x,y)
-----------------^
compilation aborted for ARG2A.F (code 1)
Comment 1 tobias.burnus 2006-05-13 23:01:08 UTC
The following is also not caught:
-----------------------------
        subroutine foo(y)
           character(len=20) :: y
           y = 'hello world'
        end

        program test
           character(len=10) :: x
           call foo(x)
           write(*,*) 'X=',x
           pause
        end
-----------------------------

NAG's f95 spits out this error:
Error: test17.f90: Argument Y (no. 1) in reference to FOO from TEST is too short a character string
Comment 2 Andrew Pinski 2006-05-13 23:05:20 UTC
This is really a dup of bug 26227.

*** This bug has been marked as a duplicate of 26227 ***