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] 2nd argument in [D]CMPLX(x,y) must not be COMPLEX


Bootstrapped and regression tested on i386-*-freebsd.
OK for trunk and 4.4 when the branch re-opens.

2009-07-18  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/40727
	* fortran/check.c (gfc_check_cmplx, gfc_check_dcmplx): Add check that
	the optional second argument isn't of COMPLEX type.

2009-07-18  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/40727
	* gfortran.dg/intrinsic_cmplx.f90: New test.

-- 
Steve
Index: gcc/fortran/check.c
===================================================================
--- gcc/fortran/check.c	(revision 149777)
+++ gcc/fortran/check.c	(working copy)
@@ -819,6 +819,15 @@ gfc_check_cmplx (gfc_expr *x, gfc_expr *
 		     gfc_current_intrinsic, &y->where);
 	  return FAILURE;
 	}
+
+      if (y->ts.type == BT_COMPLEX)
+	{
+	  gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
+		     "of either REAL or INTEGER", gfc_current_intrinsic_arg[1],
+		     gfc_current_intrinsic, &y->where);
+	  return FAILURE;
+	}
+
     }
 
   if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
@@ -977,6 +986,14 @@ gfc_check_dcmplx (gfc_expr *x, gfc_expr 
 		     gfc_current_intrinsic, &y->where);
 	  return FAILURE;
 	}
+
+      if (y->ts.type == BT_COMPLEX)
+	{
+	  gfc_error ("'%s' argument of '%s' intrinsic at %L must have a type "
+		     "of either REAL or INTEGER", gfc_current_intrinsic_arg[1],
+		     gfc_current_intrinsic, &y->where);
+	  return FAILURE;
+	}
     }
 
   return SUCCESS;
Index: gcc/testsuite/gfortran.dg/intrinsic_cmplx.f90
===================================================================
--- gcc/testsuite/gfortran.dg/intrinsic_cmplx.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/intrinsic_cmplx.f90	(revision 0)
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/40727
+program test
+  integer, parameter :: sp = kind(1.e0), dp = kind(1.d0)
+  complex(sp) :: s
+  complex(dp) :: d
+  s =  cmplx(0.e0, cmplx(0.e0,0.e0)) ! { dg-error "either REAL or INTEGER" }
+  d = dcmplx(0.d0, cmplx(0.d0,0.d0)) ! { dg-error "either REAL or INTEGER" }
+end program test

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