Re: [patch, fortran] Fix PR 87673, rejects-valid

2019-03-11 Thread Steve Kargl
On Sun, Mar 10, 2019 at 10:36:48PM +0100, Thomas Koenig wrote:
> Am 10.03.19 um 22:12 schrieb Thomas Koenig:
> 
> > You're probably right, I will fix this.  Ugh...
> 
> OK, so here is the updated test case, without the copyright stuff.
> 
> OK for trunk now? :-)
> 

Yes.  Thanks for patch.

-- 
Steve


Re: [patch, fortran] Fix PR 87673, rejects-valid

2019-03-10 Thread Thomas Koenig

Am 10.03.19 um 22:12 schrieb Thomas Koenig:


You're probably right, I will fix this.  Ugh...


OK, so here is the updated test case, without the copyright stuff.

OK for trunk now? :-)

Regards

Thomas
! { dg-do compile }
! PR 87673 - used to cause errors about non-pure functions.

module x
  implicit none
contains
  pure function foo() result(res)
character(len=:), allocatable :: res
allocate (character(bar()) :: res)
  end function foo
  pure integer function bar()
bar = 1
  end function bar
end module x


Re: [patch, fortran] Fix PR 87673, rejects-valid

2019-03-10 Thread Thomas Koenig

Am 10.03.19 um 21:15 schrieb Steve Kargl:

On Sun, Mar 10, 2019 at 09:04:18PM +0100, Thomas Koenig wrote:


! { 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


Copyright notice?


This is what I copied from the PR.


If it isn't some version of gpl or lgpl, then you might need
to either get approval from FSF, get Richard Townshend to
put the code that demonstrate the code under a gpl compatible
copyright, or rewrite the example that demonstrates the bug.


You're probably right, I will fix this.  Ugh...


BTW, I think Ian's bug report is actually a duplicate of
another PR, but don't recall which one.


It was marked as a duplicate of PR 87734, but I unmarked it
because PR 87734 is fixed on trunk and this one is not :-)

Regards

Thomas



Re: [patch, fortran] Fix PR 87673, rejects-valid

2019-03-10 Thread Steve Kargl
On Sun, Mar 10, 2019 at 09:04:18PM +0100, Thomas Koenig wrote:

> ! { 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

Copyright notice?

If it isn't some version of gpl or lgpl, then you might need
to either get approval from FSF, get Richard Townshend to 
put the code that demonstrate the code under a gpl compatible
copyright, or rewrite the example that demonstrates the bug.

BTW, I think Ian's bug report is actually a duplicate of
another PR, but don't recall which one.

-- 
Steve


[patch, fortran] Fix PR 87673, rejects-valid

2019-03-10 Thread Thomas Koenig

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  

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

2019-03-10  Thomas Koenig  

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