In testing gfortran's capacity to deal with iso_varying_string, it was found
that the error "Specification function 'len_' at (1) must be PURE" was produced
- see testcase below.  This is obviously incorrect because elemental functions
are pure.

The patch and the testcase appear below.

Paul Thomas

! { dg-do compile }
! Tests the fix for elemental functions not being allowed in
! specification expressions in pure procedures.
!
! Testcase from iso_varying_string by Rich Townsend <[EMAIL PROTECTED]>
! The allocatable component has been changed to a pointer for this testcase.
!
module iso_varying_string

  type varying_string
     private
     character(LEN=1), dimension(:), pointer :: chars
  end type varying_string

  interface len
     module procedure len_
  end interface len

contains

  pure function char_auto (string) result (char_string)
    type(varying_string), intent(in) :: string
    character(LEN=len(string))       :: char_string ! Error was here
  end function char_auto

  elemental function len_ (string) result (length)
    type(varying_string), intent(in) :: string
    integer                          :: length
  end function len_

end module iso_varying_string

Index: gcc/fortran/expr.c
===================================================================
*** gcc/fortran/expr.c  (revision 112139)
--- gcc/fortran/expr.c  (working copy)
*************** external_spec_function (gfc_expr * e)
*** 1636,1642 ****
        return FAILURE;
      }

!   if (!f->attr.pure)
      {
        gfc_error ("Specification function '%s' at %L must be PURE", f->name,
                 &e->where);
--- 1636,1642 ----
        return FAILURE;
      }

!   if (!f->attr.pure && !f->attr.elemental)
      {
        gfc_error ("Specification function '%s' at %L must be PURE", f->name,
                 &e->where);


-- 
           Summary: Elemental functions not permitted in initialization
                    expressions
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: pault at gcc dot gnu dot org
        ReportedBy: pault at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26741

Reply via email to