This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, Fortran] PR 34495 - Add -std=f95/f2003 diagnostics for real/float ...


This fixes the easier part of PR34495:

gfortran -std=f95 allowed REAL(), DBLE() and CMPLX() in initialization
expressions while the Fortran 95 standard does not.

Now, this is properly diagnosed.

Additionally, FLOAT and SNGL were marked as GFC_STD_F77, they are G77
extensions and should thus be marked as GFC_STD_GNU.

Build and regression tested on x86-64-linux with no failures (except for
the old common_6.f90 [PR33375] and ltrans-7.f90 [PR34413]).

OK for the trunk?

Tobias
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.

Index: gcc/fortran/intrinsic.c
===================================================================
--- gcc/fortran/intrinsic.c	(revision 130991)
+++ gcc/fortran/intrinsic.c	(working copy)
@@ -2047,11 +2047,11 @@ add_functions (void)
 	     gfc_check_fn_c, gfc_simplify_realpart, gfc_resolve_realpart,
 	     a, BT_UNKNOWN, dr, REQUIRED);
 
-  add_sym_1 ("float", GFC_ISYM_REAL, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_F77,
+  add_sym_1 ("float", GFC_ISYM_REAL, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_GNU,
 	     gfc_check_i, gfc_simplify_float, NULL,
 	     a, BT_INTEGER, di, REQUIRED);
 
-  add_sym_1 ("sngl", GFC_ISYM_REAL, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_F77,
+  add_sym_1 ("sngl", GFC_ISYM_REAL, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_GNU,
 	     NULL, gfc_simplify_sngl, NULL,
 	     a, BT_REAL, dd, REQUIRED);
 
@@ -3388,6 +3388,14 @@ gfc_intrinsic_func_interface (gfc_expr *
   if (check_intrinsic_standard (name, isym->standard, &expr->where) == FAILURE)
     return MATCH_ERROR;
 
+  if ((isym->id == GFC_ISYM_REAL || isym->id == GFC_ISYM_DBLE
+       || isym->id == GFC_ISYM_CMPLX)
+      && gfc_init_expr
+      && gfc_notify_std (GFC_STD_F2003, "Fortran 2003: Function '%s' "
+			 "as initialization expression at %L", name,
+			 &expr->where) == FAILURE)
+    return MATCH_ERROR;
+
   gfc_current_intrinsic_where = &expr->where;
 
   /* Bypass the generic list for min and max.  */
Index: gcc/testsuite/gfortran.dg/initialization_16.f90
===================================================================
--- gcc/testsuite/gfortran.dg/initialization_16.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/initialization_16.f90	(revision 0)
@@ -0,0 +1,15 @@
+! { dg-do compile }
+! { dg-options "-std=f95 -Wall" }
+!
+! PR fortran/34495
+!
+! Check for invalid Fortran 95 initialization expressions
+!
+program main
+  implicit none
+  real, parameter :: r1 = real(33)    ! { dg-error "Fortran 2003: Function 'real' as initialization expression" } 
+  real, parameter :: r2 = dble(33)    ! { dg-error "Fortran 2003: Function 'dble' as initialization expression" }
+  real, parameter :: r4 = cmplx(33,33)! { dg-error "Fortran 2003: Function 'cmplx' as initialization expression" }
+  print *, sngl(1.0d0) ! { dg-error "not included in the selected standard" }
+  print *, float(1.0)  ! { dg-error "not included in the selected standard" }
+end program main

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]