Bug 42550 - Unable to give initial value 2**0.5 to a real varable
Summary: Unable to give initial value 2**0.5 to a real varable
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-30 00:41 UTC by Debian GCC Maintainers
Modified: 2010-01-17 20:54 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.5.0
Known to fail: 4.3.4 4.4.3
Last reconfirmed: 2009-12-30 00:54:25


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Debian GCC Maintainers 2009-12-30 00:41:07 UTC
not seen on trunk, 4.4 branch prints an error message, 4.3 ICEs:

$ cat myProg.f95
PROGRAM myProg
  REAL :: sqrt2 = 2**0.5
  PRINT*, sqrt2
END PROGRAM myProg

$ gfortran-4.3 myProg.f95
myProg.f95: In function 'myprog':
myProg.f95:1: internal compiler error: in gfc_conv_constant, at fortran/trans-const.c:296
Please submit a full bug report,
with preprocessed source if appropriate.

$ gfortran-4.4 myProg.f95
myProg.f95:2.17:

  REAL :: sqrt2 = 2**0.5
                 1
Error: non-constant initialization expression at (1)
Comment 1 Daniel Franke 2009-12-30 00:54:25 UTC
Confirmed for 4.4.3 (20091229).

If sqrt2 is marked as PARAMETER, both 4.3.4 and 4.4.3 accept the code without further problems.
Comment 2 kargl 2009-12-30 00:55:25 UTC
Code compiles fine on trunk, and a sensible error is emitted
when compiled with -std=f95.

troutmask:sgk[215] cat we.f90
PROGRAM myProg
  REAL :: sqrt2 = 2**0.5
  PRINT*, sqrt2
END PROGRAM myProg

troutmask:sgk[216] gfc4x -o z we.f90
troutmask:sgk[217] ./z
   1.4142135    
troutmask:sgk[218] gfc4x -o z -std=f95 we.f90
we.f90:2.24:

  REAL :: sqrt2 = 2**0.5
                        1
Error: Fortran 2003: Noninteger exponent in an initialization expression at (1)

This was fixed by

2009-03-29  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/38823
	* gfortran.h: Add ARITH_PROHIBIT to arith enum.
	expr.c (gfc_match_init_expr): Add global variable init_flag to
	flag matching an initialization expression.
	(check_intrinsic_op): Move no longer reachable error message to ...
	* arith.c (arith_power): ... here.  Remove gfc_ prefix in
	gfc_arith_power.  Use init_flag.  Allow constant folding of x**y
	when y is REAL or COMPLEX.
	(eval_intrinsic): Remove restriction that y in x**y must be INTEGER
	for constant folding.
	* gfc_power: Update gfc_arith_power to arith_power

If someone wants to backport the patch, you're welcomed to do so.
Please check that initializations aren't broke by your backport
(this is harder than one might think).
Comment 3 kargl 2009-12-30 00:59:24 UTC
Note comment #16 from PR 38823.
Comment 4 kargl 2010-01-16 23:18:17 UTC
This was fixed in March 2009 on trunk.  With the pending
release of 4.4.3 and the current state of trunk, I see
no reason to back port this.
Comment 5 kargl 2010-01-17 20:54:04 UTC
Fixed on trunk.  Not backport.