From 556cc98633c579eadc1732a0edaeecd7079f3336 Mon Sep 17 00:00:00 2001
From: kargl <kargl@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Mon, 12 Dec 2005 20:13:37 +0000
Subject: [PATCH]         PR fortran/25078         * match.c
 (gfc_match_equivalence):  Count number of objects.

        gfortran.dg/equiv_5.f90:  New test.



git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@108426 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/fortran/ChangeLog                 |  5 +++++
 gcc/fortran/match.c                   | 12 ++++++++++++
 gcc/testsuite/ChangeLog               |  5 +++++
 gcc/testsuite/gfortran.dg/equiv_5.f90 |  7 +++++++
 4 files changed, 29 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/equiv_5.f90

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index fa055ea0ae85..d480b6ff5338 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,8 @@
+2005-12-12  Steven G. Kargl  <kargls@comcast.net>
+
+	PR fortran/25078
+	* match.c (gfc_match_equivalence):  Count number of objects.
+
 2005-12-11  Aldy Hernandez  <aldyh@redhat.com>
 
         * lang.opt: Add RejectNegative to ffixed-form and ffree-form.
diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index 8ca7ed6adaaf..fd4fe33cf129 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -2599,6 +2599,7 @@ gfc_match_equivalence (void)
   match m;
   gfc_common_head *common_head = NULL;
   bool common_flag;
+  int cnt;
 
   tail = NULL;
 
@@ -2616,6 +2617,7 @@ gfc_match_equivalence (void)
 
       set = eq;
       common_flag = FALSE;
+      cnt = 0;
 
       for (;;)
 	{
@@ -2625,6 +2627,9 @@ gfc_match_equivalence (void)
 	  if (m == MATCH_NO)
 	    goto syntax;
 
+	  /*  count the number of objects.  */
+	  cnt++;
+
 	  if (gfc_match_char ('%') == MATCH_YES)
 	    {
 	      gfc_error ("Derived type component %C is not a "
@@ -2655,6 +2660,7 @@ gfc_match_equivalence (void)
 
 	  if (gfc_match_char (')') == MATCH_YES)
 	    break;
+
 	  if (gfc_match_char (',') != MATCH_YES)
 	    goto syntax;
 
@@ -2662,6 +2668,12 @@ gfc_match_equivalence (void)
 	  set = set->eq;
 	}
 
+      if (cnt < 2)
+	{
+	  gfc_error ("EQUIVALENCE at %C requires two or more objects");
+	  goto cleanup;
+	}
+
       /* If one of the members of an equivalence is in common, then
 	 mark them all as being in common.  Before doing this, check
 	 that members of the equivalence group are not in different
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d2740e7e8147..370065ddfa42 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2005-12-12  Steven G. Kargl  <kargls@comcast.net>
+
+	PR fortran/25078
+	gfortran.dg/equiv_5.f90:  New test.
+
 2005-12-12  Daniel Berlin  <dberlin@dberlin.org>
 
 	* gcc.dg/tree-ssa/ssa-pre-2.c: Update due to reassociation changes.
diff --git a/gcc/testsuite/gfortran.dg/equiv_5.f90 b/gcc/testsuite/gfortran.dg/equiv_5.f90
new file mode 100644
index 000000000000..70b458bea613
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/equiv_5.f90
@@ -0,0 +1,7 @@
+! { dg-do compile }
+! PR fortran/25078
+! An equivalence statement requires two or more objcets.
+program a
+  real x
+  equivalence(x) ! { dg-error "two or more objects" }
+end program a
-- 
GitLab