https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91497

--- Comment #4 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Tue, Aug 20, 2019 at 03:28:29PM +0000, kargl at gcc dot gnu.org wrote:
> 
> --- Comment #1 from kargl at gcc dot gnu.org ---
> Unfortunately, -Wconversion has a problem with false positives.
> You can, of course, avoid the problem by not using the option.
> 

This diff will silence warnings for explicit conversion
using REAL() and INT() for the -Wconversion option.  It
does not silence warnings for -Wconversion-extra.

Index: gcc/fortran/simplify.c
===================================================================
--- gcc/fortran/simplify.c      (revision 274676)
+++ gcc/fortran/simplify.c      (working copy)
@@ -3572,6 +3572,7 @@ static gfc_expr *
 simplify_intconv (gfc_expr *e, int kind, const char *name)
 {
   gfc_expr *result = NULL;
+  int tmp;

   /* Convert BOZ to integer, and return without range checking.  */
   if (e->ts.type == BT_BOZ)
@@ -3585,7 +3586,12 @@ simplify_intconv (gfc_expr *e, int kind, const char *n
   if (e->expr_type != EXPR_CONSTANT)
     return NULL;

+  /* For explicit conversion, turn off -Wconversion warning.  Leave the 
+     warning if -Wconversion-extra is used.  */
+  tmp = warn_conversion;
+  warn_conversion = 0;
   result = gfc_convert_constant (e, BT_INTEGER, kind);
+  warn_conversion = tmp;
   if (result == &gfc_bad_expr)
     return &gfc_bad_expr;

@@ -6467,7 +6473,7 @@ gfc_expr *
 gfc_simplify_real (gfc_expr *e, gfc_expr *k)
 {
   gfc_expr *result = NULL;
-  int kind;
+  int kind, tmp;

   /* Convert BOZ to real, and return without range checking.  */
   if (e->ts.type == BT_BOZ)
@@ -6495,7 +6501,12 @@ gfc_simplify_real (gfc_expr *e, gfc_expr *k)
   if (e->expr_type != EXPR_CONSTANT)
     return NULL;

+  /* For explicit conversion, turn off -Wconversion warning.  Leave the 
+     warning if -Wconversion-extra is used.  */
+  tmp = warn_conversion;
+  warn_conversion = 0;
   result = gfc_convert_constant (e, BT_REAL, kind);
+  warn_conversion = tmp;
   if (result == &gfc_bad_expr)
     return &gfc_bad_expr;

Reply via email to