re PR fortran/54234 (-Wconversion or -Wconversion-extra should warn for CMPLX(dp...
authorTobias Burnus <burnus@net-b.de>
Tue, 14 Aug 2012 10:22:06 +0000 (12:22 +0200)
committerTobias Burnus <burnus@gcc.gnu.org>
Tue, 14 Aug 2012 10:22:06 +0000 (12:22 +0200)
2012-08-14  Tobias Burnus  <burnus@net-b.de>

        PR fortran/54234
        * check.c (gfc_check_cmplx): Add -Wconversion warning
        when converting higher-precision REAL to default-precision
        CMPLX without kind= parameter.

2012-08-14  Tobias Burnus  <burnus@net-b.de>

        PR fortran/54234
        * gfortran.dg/warn_conversion_4.f90: New.

From-SVN: r190378

gcc/fortran/ChangeLog
gcc/fortran/check.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/warn_conversion_4.f90 [new file with mode: 0644]

index b0fe19019cb40daa153efee9175043d47c310871..3a62890fde501446f8a2ef6c55e8f6c2585cccc9 100644 (file)
@@ -1,3 +1,10 @@
+2012-08-14  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/54234
+       * check.c (gfc_check_cmplx): Add -Wconversion warning
+       when converting higher-precision REAL to default-precision
+       CMPLX without kind= parameter.
+
 2012-08-12  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/54221
index c5bf79b8fea1f793ebced17b2c4d5b36267a24ee..2235b52d6d3cfc31c015e5b2878cab9cfac1950b 100644 (file)
@@ -1278,6 +1278,17 @@ gfc_check_cmplx (gfc_expr *x, gfc_expr *y, gfc_expr *kind)
   if (kind_check (kind, 2, BT_COMPLEX) == FAILURE)
     return FAILURE;
 
+  if (!kind && gfc_option.gfc_warn_conversion
+      && x->ts.type == BT_REAL && x->ts.kind > gfc_default_real_kind)
+    gfc_warning_now ("Conversion from %s to default-kind COMPLEX(%d) at %L "
+                    "might loose precision, consider using the KIND argument",
+                    gfc_typename (&x->ts), gfc_default_real_kind, &x->where);
+  else if (y && !kind && gfc_option.gfc_warn_conversion
+          && y->ts.type == BT_REAL && y->ts.kind > gfc_default_real_kind)
+    gfc_warning_now ("Conversion from %s to default-kind COMPLEX(%d) at %L "
+                    "might loose precision, consider using the KIND argument",
+                    gfc_typename (&y->ts), gfc_default_real_kind, &y->where);
+
   return SUCCESS;
 }
 
index e1e12837124bc3bd13cf38e5095c7a825d9c23f9..1ec4e0de34ca500a917da5976c170117456be2a5 100644 (file)
@@ -1,3 +1,8 @@
+2012-08-14  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/54234
+       * gfortran.dg/warn_conversion_4.f90: New.
+
 2012-08-14  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/53411
diff --git a/gcc/testsuite/gfortran.dg/warn_conversion_4.f90 b/gcc/testsuite/gfortran.dg/warn_conversion_4.f90
new file mode 100644 (file)
index 0000000..f911741
--- /dev/null
@@ -0,0 +1,18 @@
+! { dg-do compile }
+! { dg-options "-Wconversion" }
+!
+! PR fortran/54234
+!
+!
+module fft_mod
+  implicit none
+  integer, parameter :: dp=kind(0.0d0)
+contains
+  subroutine test
+    integer :: x
+    x = int (abs (cmplx(2.3,0.1)))
+    x = int (abs (cmplx(2.3_dp,0.1))) ! { dg-warning "Conversion from REAL.8. to default-kind COMPLEX.4. at .1. might loose precision, consider using the KIND argument" }
+    x = int (abs (cmplx(2.3,0.1_dp))) ! { dg-warning "Conversion from REAL.8. to default-kind COMPLEX.4. at .1. might loose precision, consider using the KIND argument" }
+    x = int (abs (cmplx(2.3_dp,0.1_dp))) ! { dg-warning "Conversion from REAL.8. to default-kind COMPLEX.4. at .1. might loose precision, consider using the KIND argument" }
+  end subroutine test
+end module fft_mod