Bug 34495 - [4.3 Regression] accepts invalid initialization expressions withTRANSFER
Summary: [4.3 Regression] accepts invalid initialization expressions withTRANSFER
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Daniel Franke
URL: http://gcc.gnu.org/ml/fortran/2007-12...
Keywords: accepts-invalid, diagnostic
Depends on:
Blocks: 31237
  Show dependency treegraph
 
Reported: 2007-12-16 13:37 UTC by Thomas Koenig
Modified: 2007-12-18 23:42 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-12-17 22:34:31


Attachments
Patch - only for the REAL()/CMPLX() diagnostics (606 bytes, patch)
2007-12-16 15:14 UTC, Tobias Burnus
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2007-12-16 13:37:51 UTC
Adapted from a test case from c.l.f, from James van Buskirk
:
$ cat foo.f90 
program main
   integer, parameter :: ipi = 1078530011
   real pi
   parameter(pi=transfer(ipi,pi))
   real, parameter :: z = transfer(ipi,z)
   real, parameter :: y = real(1,kind(y))

   write(*,*) pi, z, y
end
$ gfortran -std=f95 -pedantic foo.f90 
$ ./a.out
   3.1415927       3.1415927      1.00000000 

JvB's explanation:

# the second
# and third treat transfer as a specification inquiry even thought
# that is not permitted even in f03, and the fourth has that pesky
# REAL intrinsic, which is not an elemental function of type integer
# or character.

gfortran 4.2 still generates some error messages:

$ gfortran-4.2 foo.f90 
foo.f90:4.29:

   parameter(pi=transfer(ipi,pi))
                            1
Error: Parameter 'pi' at (1) has not been declared or is a variable, which does not reduce to a constant expression
foo.f90:5.35:

   real, parameter :: z = transfer(ipi,z)
                                  1
Error: TRANSFER intrinsic not implemented for initialization at (1)
Comment 1 Tobias Burnus 2007-12-16 14:35:23 UTC
Confirm. Though other compilers have better error messages than 4.2 had. (These are all shown by default, i.e. none of the compilers below accepts it.)

NAG f95:
  Error: PARAMETER PI used before its definition is complete
g95:
  Error: PARAMETER value is used before being defined at (1)
ifort:
  Error: A PARAMETER must not be defined in terms of itself.   [PI]
(sunf95 and openf95 have also not a good message.)

I think for -std=f95 one needs another error. NAG f95 prints:
  Error: The REAL function is not permitted in an initialisation expression

I am also not sure whether I would call the following a regression:
> Error: TRANSFER intrinsic not implemented for initialization at (1)
Comment 2 Tobias Burnus 2007-12-16 15:14:56 UTC
Created attachment 14779 [details]
Patch - only for the REAL()/CMPLX() diagnostics
Comment 3 Tobias Burnus 2007-12-16 22:13:13 UTC
Subject: Bug 34495

Author: burnus
Date: Sun Dec 16 22:12:55 2007
New Revision: 130994

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130994
Log:
2007-12-16  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34495
        * intrinsic.c (add_functions): Mark float and sngl as STD_GNU.
        (gfc_intrinsic_func_interface): Reject REAL, DBLE and CMPLX
        in initialization expressions for -std=f95.

2007-12-16  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34495
        * gfortran.dg/initialization_16.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/initialization_16.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/intrinsic.c
    trunk/gcc/testsuite/ChangeLog

Comment 4 Tobias Burnus 2007-12-16 22:14:32 UTC
Comment on attachment 14779 [details]
Patch - only for the REAL()/CMPLX() diagnostics

Still to do: Adding/Re-adding an error for:
  Error: PARAMETER PI used before its definition is complete
Comment 5 Tobias Burnus 2007-12-17 14:35:06 UTC
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/2ad94287d7f8a6f0/

Related for non parameters:
  real :: pi = transfer(123,pi)
Comment 6 Tobias Burnus 2007-12-17 18:45:34 UTC
Example why it should be forbidden also for -std=gnu/legacy:

implicit none
dimension :: i1(5)
integer :: i1 = transfer([1,2,3,4,5], i1)
integer :: i2 = transfer([1,2,3,4,5], i2)
dimension :: i2(5)
print *, i1 ! prints: 1 2 3 4 5
print *, i2 ! prints: 1 1 1 1 1
end
Comment 7 Tobias Burnus 2007-12-17 19:01:24 UTC
In words of the standard (esp. last sentence):

"If an initialization expression includes a specification inquiry that depends on a type parameter or an array bound of an entity specified in the same specification-part, the type parameter or array bound shall be specified in a prior specification of the specification-part. The prior specification may be to the left of the specification inquiry in the same statement, but shall not be within the same entity-decl."
Comment 8 Daniel Franke 2007-12-17 22:34:31 UTC
Mine. Got a patch, but one more error message to fix ... 
Comment 9 Daniel Franke 2007-12-18 23:40:11 UTC
Subject: Bug 34495

Author: dfranke
Date: Tue Dec 18 23:39:56 2007
New Revision: 131047

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131047
Log:
gcc/fortran:
2007-12-19  Daniel Franke  <franke.daniel@gmail.com>

        PR fortran/34495
        * expr.c (check_init_expr): Check whether variables with flavor
        FL_PARAMETER do have a value assigned. Added error messages where
        appropriate.
        * simplify.c (gfc_simplify_transfer): Added check if the MOLD
        argument is a constant if working with initialization
        expressions.

gcc/testsuite:
2007-12-19  Daniel Franke  <franke.daniel@gmail.com>

        PR fortran/34495
        * gfortran.dg/transfer_simplify_2.f90: Fixed invalid initialization
	expressions.
        * gfortran.dg/transfer_simplify_7.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/transfer_simplify_7.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/simplify.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/transfer_simplify_2.f90

Comment 10 Daniel Franke 2007-12-18 23:41:14 UTC
Fixed in trunk. Closing.