Blame SOURCES/0005-Allow-comparisons-between-INTEGER-and-REAL.patch

3db796
From ab5aa6f7c04e7193c5387bc74db2605c4dc07f01 Mon Sep 17 00:00:00 2001
3db796
From: Jim MacArthur <jim.macarthur@codethink.co.uk>
3db796
Date: Thu, 4 Feb 2016 16:46:46 +0000
3db796
Subject: [PATCH 05/23] Allow comparisons between INTEGER and REAL
3db796
3db796
This feature is enabled with the `-std=extra-legacy` compiler flag.
3db796
---
3db796
        0005-Allow-comparisons-between-INTEGER-and-REAL.patch
3db796
3db796
diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
3db796
index 4f2d216..fd0d280 100644
3db796
--- a/gcc/fortran/check.c
3db796
+++ b/gcc/fortran/check.c
3db796
@@ -901,6 +901,24 @@ gfc_check_allocated (gfc_expr *array)
3db796
 }
3db796
 
3db796
 
3db796
+/* Attempt to promote types of A and B so that they are
3db796
+   equivalent, if possible.  */
3db796
+void
3db796
+promote_types (gfc_expr *a, gfc_expr *b)
3db796
+{
3db796
+  if (a->ts.type == b->ts.type)
3db796
+    return;
3db796
+  if (a->ts.type == BT_REAL && b->ts.type == BT_INTEGER)
3db796
+    {
3db796
+      gfc_convert_type_warn (b, &a->ts, 2, 1);
3db796
+      return;
3db796
+    }
3db796
+  if (a->ts.type == BT_INTEGER && b->ts.type == BT_REAL)
3db796
+    {
3db796
+      gfc_convert_type_warn (a, &b->ts, 2, 1);
3db796
+    }
3db796
+}
3db796
+
3db796
 /* Common check function where the first argument must be real or
3db796
    integer and the second argument must be the same as the first.  */
3db796
 
3db796
@@ -910,6 +928,9 @@ gfc_check_a_p (gfc_expr *a, gfc_expr *p)
3db796
   if (!int_or_real_check (a, 0))
3db796
     return false;
3db796
 
3db796
+  if (gfc_option.allow_std & GFC_STD_EXTRA_LEGACY)
3db796
+    promote_types(a, p);
3db796
+
3db796
   if (a->ts.type != p->ts.type)
3db796
     {
3db796
       gfc_error ("%qs and %qs arguments of %qs intrinsic at %L must "