Hello world,

the attached patch fixes a 7/8/9 regression by removing
the call to gfc_resovle_expr during matching.  It turned
out that gfc_resolve_expr depends on some conditions
that are not yet met during the matching phase.

Fortunately, the bug that this originally fixed (PR 82049)
has been fixed another way on trunk, so that just removing
this part works.  For backporting, it would be necessary to
check if the fix(es) would need to be backported if they haven't
been already - probably one or several of Harald's patches.

So, OK for trunk? OK for backporting?

Regards

        Thomas

2019-03-10  Thomas Koenig  <tkoe...@gcc.gnu.org>

        PR fortran/87673
        * match.c (gfc_match_type_spec): Remove call to
        gfc_resolve_expr for character length.

2019-03-10  Thomas Koenig  <tkoe...@gcc.gnu.org>

        PR fortran/87673
        * gfortran.dg/charlen_17.f90: New patch.
Index: match.c
===================================================================
--- match.c	(Revision 269552)
+++ match.c	(Arbeitskopie)
@@ -2122,8 +2122,6 @@ gfc_match_type_spec (gfc_typespec *ts)
       ts->type = BT_CHARACTER;
 
       m = gfc_match_char_spec (ts);
-      if (ts->u.cl && ts->u.cl->length)
-	gfc_resolve_expr (ts->u.cl->length);
 
       if (m == MATCH_NO)
 	m = MATCH_YES;
! { dg-do compile }
! PR 87673 - used to cause errors about non-pure functions.
!  A fragment from Richard Townsend's iso_varying_string, as modified by
! Ian Harvey to include F2003 language capabilities. For copyright notices
! see source at http://www.megms.com.au/download/aniso_varying_string.f90
!
module v
  TYPE, PUBLIC :: varying_string
    !> Actual storage for the string.
    CHARACTER(:,KIND=1), ALLOCATABLE, PUBLIC :: chars

  END TYPE varying_string
contains
  PURE FUNCTION char_fixed(string, length) RESULT(char_string)

    !---------------------------------------------------------------------------
    ! Characteristics

    !> The string to convert.
    TYPE(varying_string), INTENT(IN) :: string

    !> The length of the result string.
    INTEGER, INTENT(IN), OPTIONAL :: length

    !> @returns A default CHARACTER string of length @a length if @a
    !! length is present, or the length of @a string if not, with the same
    !! sequence of characters as @a string up to the length of the result,
    !! padded with blanks on the right if necessary.
    !!
    !! Because @a length is OPTIONAL per the description of CHAR in
    !! ISO1539-2 3.4.3, it cannot be used in a specification
    !! expression (F2008 7.1.11p2(2)).  Consequently the result of this
    !! function needs to be deferred.
    !!
    !! It is possible that the specification of CHAR in ISO1539-2 is
    !! a mistake - the intent may have been for it to be two separate
    !! specific procedures, one with one argument, one with two, and
    !! no OPTIONAL arguments.

    CHARACTER(:, KIND=1), allocatable :: char_string
!    integer :: klen

    !***************************************************************************

!    klen = get_char_result_length(len(string%chars), length)
!    ALLOCATE( CHARACTER(klen) ::  char_string ) ! This is OK

    ALLOCATE( CHARACTER(get_char_result_length(len(string%chars), length)) ::  &
         char_string )

    char_string(:) = string%chars

  END FUNCTION char_fixed
  PURE FUNCTION get_char_result_length(string_length, desired_length) RESULT(l)

    !---------------------------------------------------------------------------
    ! Characteristics

    !> The length of the @a string argument to char_fixed.s
    INTEGER, INTENT(IN) :: string_length

    !> The optional desired length of the result from char_fixed.
    INTEGER, INTENT(IN), OPTIONAL :: desired_length

    !> @returns @a desired_length, if present, otherwise @a string_length.
    INTEGER :: l

    !***************************************************************************

    IF (PRESENT(desired_length)) THEN
      l = desired_length
    ELSE
      l = string_length
    END IF

  END FUNCTION get_char_result_length
end module

Reply via email to