PR fortran/86059 -- NULL() cannot be in array constructor

Message ID 20180608003706.GA34217@troutmask.apl.washington.edu
State New
Headers show
Series
  • PR fortran/86059 -- NULL() cannot be in array constructor
Related show

Commit Message

Steve Kargl June 8, 2018, 12:37 a.m.
Regression tested on x86_64-*-freebsd.  OK to commit.

2018-06-07  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/86059 
	* array.c (match_array_cons_element): NULL() cannot be in an
	array constructor.

2018-06-07  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/86059 
	* gfortran.dg/associate_30.f90: Remove code tested ...
	* gfortran.dg/pr67803.f90: Ditto.
	* gfortran.dg/pr67805.f90: Ditto.
	* gfortran.dg/pr86059.f90: ... here.  New test.

-- 
Steve

Comments

Thomas Koenig June 8, 2018, 7:01 p.m. | #1
Hi Steve,

> Regression tested on x86_64-*-freebsd.  OK to commit.


OK, and thanks!

	Thomas
Steve Kargl June 8, 2018, 7:12 p.m. | #2
On Fri, Jun 08, 2018 at 09:01:50PM +0200, Thomas Koenig wrote:
> > Regression tested on x86_64-*-freebsd.  OK to commit.

> 

> OK, and thanks!


Thanks.  Committed to trunk.

-- 
Steve

Patch

Index: gcc/fortran/array.c
===================================================================
--- gcc/fortran/array.c	(revision 261285)
+++ gcc/fortran/array.c	(working copy)
@@ -1098,6 +1098,15 @@  match_array_cons_element (gfc_constructor_base *result
   if (m != MATCH_YES)
     return m;
 
+  if (expr->expr_type == EXPR_FUNCTION
+      && expr->ts.type == BT_UNKNOWN
+      && strcmp(expr->symtree->name, "null") == 0)
+   {
+      gfc_error ("NULL() at %C cannot appear in an array constructor");
+      gfc_free_expr (expr);
+      return MATCH_ERROR;
+   }
+
   gfc_constructor_append_expr (result, expr, &gfc_current_locus);
   return MATCH_YES;
 }
Index: gcc/testsuite/gfortran.dg/associate_30.f90
===================================================================
--- gcc/testsuite/gfortran.dg/associate_30.f90	(revision 261285)
+++ gcc/testsuite/gfortran.dg/associate_30.f90	(working copy)
@@ -8,8 +8,3 @@ 
       associate (x => null())   ! { dg-error "cannot be NULL()" }
       end associate
    end subroutine
-
-   subroutine s2
-      associate (x => [null()]) ! { dg-error "has no type" }
-      end associate
-   end subroutine
Index: gcc/testsuite/gfortran.dg/pr67803.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr67803.f90	(revision 261285)
+++ gcc/testsuite/gfortran.dg/pr67803.f90	(working copy)
@@ -10,5 +10,4 @@  program p
   x = '0' // [character :: 1d1]     ! { dg-error "Incompatible typespec for" }
   x = '0' // [character :: (0.,1.)] ! { dg-error "Incompatible typespec for" }
   x = '0' // [character :: .true.]  ! { dg-error "Incompatible typespec for" }
-  x = '0' // [character :: null()]  ! { dg-error "Incompatible typespec for" }
 end
Index: gcc/testsuite/gfortran.dg/pr67805.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr67805.f90	(revision 261285)
+++ gcc/testsuite/gfortran.dg/pr67805.f90	(working copy)
@@ -22,7 +22,6 @@  subroutine p
    s = [character([1.]) :: 'x', 'y']      ! { dg-error "INTEGER expression expected" }
    s = [character([1d1]) :: 'x', 'y']     ! { dg-error "INTEGER expression expected" }
    s = [character([(0.,1.)]) :: 'x', 'y'] ! { dg-error "INTEGER expression expected" }
-   s = [character([null()]) :: 'x', 'y']  ! { dg-error "INTEGER expression expected" }
    s =  [character(null()) :: 'x', 'y']   ! { dg-error "INTEGER expression expected" }
    call foo(s)
 end subroutine p
Index: gcc/testsuite/gfortran.dg/pr86059.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr86059.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr86059.f90	(working copy)
@@ -0,0 +1,8 @@ 
+! { dg-do compile }
+! PR fortran/86059
+program foo
+   integer :: i(2) = [ null(), 1 ]           ! { dg-error "cannot appear in an array constructor" }
+   integer :: j(2) = [ (null(), n = 1, 2) ]  ! { dg-error "cannot appear in an array constructor" }
+   integer k(2)
+   k = 42 + [1, null()]                      ! { dg-error "cannot appear in an array constructor" }
+end program foo