From acc75ae36ea717cc0792ffec8f6336c4a73da7b3 Mon Sep 17 00:00:00 2001 From: Erik Edelmann Date: Wed, 18 May 2005 22:20:31 +0300 Subject: [PATCH] array.c (gfc_match_array_constructor): Support [ ... 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 | 5 +++++ gcc/fortran/array.c | 19 ++++++++++++++++--- gcc/testsuite/ChangeLog | 5 +++++ .../gfortran.dg/array_constructor_1.f90 | 17 +++++++++++++++++ .../gfortran.dg/array_constructor_2.f90 | 8 ++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/array_constructor_1.f90 create mode 100644 gcc/testsuite/gfortran.dg/array_constructor_2.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 714024f8023..31179f06a02 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2005-05-18 Erik Edelmann + + * array.c (gfc_match_array_constructor): Support [ ... ] + style array constructors. + 2005-05-18 Tobias Schl"uter * f95-lang.c (gfc_init_builtin_functions): Define BUILT_IN_TRUNC diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index dc660d45580..f6284408567 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -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: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 45bdf065123..7ad8521234b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-05-12 Erik Edelmann + + * gfortran.dg/array_constructor_1.f90: New test. + * gfortran.dg/array_constructor_2.f90: New test. + 2005-05-18 Feng Wang 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 index 00000000000..20452f3d3fa --- /dev/null +++ b/gcc/testsuite/gfortran.dg/array_constructor_1.f90 @@ -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 index 00000000000..ffed1f0fb61 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/array_constructor_2.f90 @@ -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 -- 2.30.2