This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[patch,fortran] Allow noninteger/noncharacter arguments to intrinsic functions for initialization expressions
- From: Tobias Burnus <burnus at net-b dot de>
- To: "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 23 Nov 2006 22:41:14 +0100
- Subject: [patch,fortran] Allow noninteger/noncharacter arguments to intrinsic functions for initialization expressions
Hi,
since we started to emit an error with "-std=f95" rather than only with
"-pedantic -std=f95" if a noninteger/noncharacter argument is used in an
elemental intrinsic function in an initialization expressions, we don't
accept anymore:
-std=f2003
real, parameter :: a = acos(1.0)
This is therefore a kind of regression. (It is only a kind of regression
since we accepted it for the wrong reasons.)
Fortran 2003 standard states in
"7.1.7 Initialization expression":
[Allowed is] "a reference to an elemental standard intrinsic function,
where each argument is an initialization expression"
The Fortran 95 standard was stricter ("7.1.6.1 Constant expression"):
"An initialization expression is a constant expression in which the
exponentiation operation is
permitted only with an integer power, and each primary is
[...]
(4) An elemental intrinsic function reference of type integer or
character where each
argument is an initialization expression of type integer or character"
I attached a patch which changes GFC_STD_GNU to GFC_STF_F2003 and filled
PR 29962 as reminder to check whether there is indeed no difference
between GFC_STD_GNU and GFC_STF_F2003, to add a check whether the
intrinsic function is indeed elemental, etc.
Ok for the trunk?
Tobias
fortran/
2006-11-23 Tobias Burnus <burnus@net-b.de>
* intrinsic.c (gfc_intrinsic_func_interface): Allow
noninteger/nonreal arguments for intrinsics in initialization
expressions with -std=f2003.
testsuite/
2006-11-23 Tobias Burnus <burnus@net-b.de>
* gfortran.dg/initialization_4.f90: Adapt dg-error.
* gfortran.dg/initialization_5.f90: New test.
Index: gcc/fortran/intrinsic.c
===================================================================
--- gcc/fortran/intrinsic.c (Revision 119134)
+++ gcc/fortran/intrinsic.c (Arbeitskopie)
@@ -3399,12 +3399,11 @@
if (gfc_init_expr && flag && gfc_init_expr_extensions (specific))
{
- if (gfc_notify_std (GFC_STD_GNU, "Extension: Evaluation of "
- "nonstandard initialization expression at %L", &expr->where)
+ if (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: Initialization "
+ "expression with an intrinsic function and noninteger/"
+ "noncharacter arguments at %L", &expr->where)
== FAILURE)
- {
- return MATCH_ERROR;
- }
+ return MATCH_ERROR;
}
check_intrinsic_standard (name, isym->standard, &expr->where);
Index: gcc/testsuite/gfortran.dg/initialization_4.f90
===================================================================
--- gcc/testsuite/gfortran.dg/initialization_4.f90 (Revision 119131)
+++ gcc/testsuite/gfortran.dg/initialization_4.f90 (Arbeitskopie)
@@ -2,5 +2,5 @@
! initialization expression, even if -std=f95 was used
! { dg-do compile }
! { dg-options "-std=f95" }
-real, parameter :: pi = 4.0*Atan(1.0) ! { dg-error "Evaluation of nonstandard initialization expression" }
+real, parameter :: pi = 4.0*Atan(1.0) ! { dg-error "intrinsic function and noninteger/noncharacter arguments" }
end
Index: gcc/testsuite/gfortran.dg/initialization_5.f90
===================================================================
--- gcc/testsuite/gfortran.dg/initialization_5.f90 (Revision 0)
+++ gcc/testsuite/gfortran.dg/initialization_5.f90 (Revision 0)
@@ -0,0 +1,7 @@
+! Check whether noninteger/noncharacter
+! arguments to intrinsic functions are allowed as
+! initialization expression with -std=f2003
+! { dg-do run }
+! { dg-options "-std=f2003" }
+real, parameter :: pi = 4.0*Atan(1.0)
+end