An entry-name obtains the elemental attribute from its containing
procedure.  F2018:C1546 prohibits an procedure from having a BIND(C)
attribute.  BIND(C) can appear on the entry-stmt line, so gfortran
needs to check for a conflict.  The attached patch does this check.
Tested on x86_64-*-freebsd.  Ok to commit?

2019-01-10  Steven G. Kargl  <ka...@gcc.gnu.org>

        PR fortran/35031
        * decl.c (gfc_match_entry): Check for F2018:C1546.  Fix nearby
        mis-indentation.
 
2019-01-10  Steven G. Kargl  <ka...@gcc.gnu.org>

        PR fortran/35031
        * gfortran.dg/pr35031.f90: new test.

-- 
Steve
Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(revision 267825)
+++ gcc/fortran/decl.c	(working copy)
@@ -7431,9 +7431,11 @@ gfc_match_entry (void)
 	      gfc_error ("Missing required parentheses before BIND(C) at %C");
 	      return MATCH_ERROR;
 	    }
-	    if (!gfc_add_is_bind_c (&(entry->attr), entry->name,
-				    &(entry->declared_at), 1))
-	      return MATCH_ERROR;
+
+	  if (!gfc_add_is_bind_c (&(entry->attr), entry->name,
+				  &(entry->declared_at), 1))
+	    return MATCH_ERROR;
+	
 	}
 
       if (!gfc_current_ns->parent
@@ -7514,6 +7516,14 @@ gfc_match_entry (void)
   if (gfc_match_eos () != MATCH_YES)
     {
       gfc_syntax_error (ST_ENTRY);
+      return MATCH_ERROR;
+    }
+
+  /* F2018:C1546 An elemental procedure shall not have the BIND attribute.  */
+  if (proc->attr.elemental && entry->attr.is_bind_c)
+    {
+      gfc_error ("ENTRY statement at %L with BIND(C) prohibited in an "
+		 "elemental procedure", &entry->declared_at);
       return MATCH_ERROR;
     }
 
Index: gcc/testsuite/gfortran.dg/pr35031.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr35031.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr35031.f90	(working copy)
@@ -0,0 +1,10 @@
+! { dg-do compile }
+elemental subroutine sub2(x)
+   integer, intent(in) :: x
+   entry sub2_c(x) bind(c)    ! { dg-error "prohibited in an elemental" }
+end subroutine sub2
+
+elemental function func2(x)
+   integer, intent(in) :: x
+   entry func2_c(x) bind(c)   ! { dg-error "prohibited in an elemental" }
+end function func2

Reply via email to