array.c (gfc_match_array_constructor): Support [ ...
authorErik Edelmann <erik.edelmann@iki.fi>
Wed, 18 May 2005 19:20:31 +0000 (22:20 +0300)
committerTobias Schlüter <tobi@gcc.gnu.org>
Wed, 18 May 2005 19:20:31 +0000 (21:20 +0200)
fortran/
* array.c (gfc_match_array_constructor): Support [ ... ]
style array constructors.
testsuite/
* gfortran.dg/array_constructor_1.f90: New test.
* gfortran.dg/array_constructor_2.f90: New test.

From-SVN: r99919

gcc/fortran/ChangeLog
gcc/fortran/array.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/array_constructor_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/array_constructor_2.f90 [new file with mode: 0644]

index 714024f80231cf3dd52d966b45d915615d5bf82c..31179f06a02c262c791be88f3b4c98012dce9c62 100644 (file)
@@ -1,3 +1,8 @@
+2005-05-18 Erik Edelmann <erik.edelmann@iki.fi>
+
+       * array.c (gfc_match_array_constructor): Support [ ... ]
+       style array constructors.
+
 2005-05-18  Tobias Schl"uter  <tobias.schlueter@physik.uni-muenchen.de>
 
        * f95-lang.c (gfc_init_builtin_functions): Define BUILT_IN_TRUNC
index dc660d45580ba44163fed38b2f44ea01dd634345..f6284408567e1d136a367277e74172e36484f3be 100644 (file)
@@ -866,14 +866,27 @@ gfc_match_array_constructor (gfc_expr ** result)
   gfc_expr *expr;
   locus where;
   match m;
+  const char *end_delim;
 
   if (gfc_match (" (/") == MATCH_NO)
-    return MATCH_NO;
+    {
+      if (gfc_match (" [") == MATCH_NO)
+        return MATCH_NO;
+      else
+        {
+          if (gfc_notify_std (GFC_STD_F2003, "New in Fortran 2003: [...] "
+                              "style array constructors at %C") == FAILURE)
+            return MATCH_ERROR;
+          end_delim = " ]";
+        }
+    }
+  else
+    end_delim = " /)";
 
   where = gfc_current_locus;
   head = tail = NULL;
 
-  if (gfc_match (" /)") == MATCH_YES)
+  if (gfc_match (end_delim) == MATCH_YES)
     goto empty;                        /* Special case */
 
   for (;;)
@@ -895,7 +908,7 @@ gfc_match_array_constructor (gfc_expr ** result)
        break;
     }
 
-  if (gfc_match (" /)") == MATCH_NO)
+  if (gfc_match (end_delim) == MATCH_NO)
     goto syntax;
 
 empty:
index 45bdf0651235391289edb5bfacff78ed3355583d..7ad8521234bc40c5ac5d505550bdcfde57c274cd 100644 (file)
@@ -1,3 +1,8 @@
+2005-05-12  Erik Edelmann  <erik.edelmann@iki.fi>
+
+       * gfortran.dg/array_constructor_1.f90: New test.
+       * gfortran.dg/array_constructor_2.f90: New test.
+
 2005-05-18  Feng Wang  <fengwang@nudt.edu.cn>
 
        PR fortran/20954
diff --git a/gcc/testsuite/gfortran.dg/array_constructor_1.f90 b/gcc/testsuite/gfortran.dg/array_constructor_1.f90
new file mode 100644 (file)
index 0000000..20452f3
--- /dev/null
@@ -0,0 +1,17 @@
+! { dg-do run }
+! Check that [...] style array constructors work
+program bracket_array_constructor
+    implicit none
+    integer :: a(4), i
+
+    a = [ 1, 2, 3, 4 ]  ! { dg-warning "array constructor" }
+    do i = 1, size(a)
+        if (a(i) /= i) call abort()
+    end do
+
+    a = [ (/ 1, 2, 3, 4 /) ]  ! { dg-warning "array constructor" }
+    do i = 1, size(a)
+        if (a(i) /= i) call abort()
+    end do
+
+end program bracket_array_constructor
diff --git a/gcc/testsuite/gfortran.dg/array_constructor_2.f90 b/gcc/testsuite/gfortran.dg/array_constructor_2.f90
new file mode 100644 (file)
index 0000000..ffed1f0
--- /dev/null
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! Check that array constructor delimiters match
+program bracket_array_constr_2
+    implicit none
+    integer :: a(4)
+    a = (/ 1, 2, 3, 4 ] ! { dg-error "array constructor" }
+    a = (/ [ 1, 2, 3, 4 /) ] ! { dg-error "array constructor" }
+end program bracket_array_constr_2