Commit cd714e1e by Fritz Reese Committed by Fritz Reese

Enable %LOC as an rvalue with -std=legacy.

	gcc/fortran/
        * primary.c (gfc_match_rvalue): Match %LOC as LOC with -std=legacy.
        * gfortran.texi: Document.

	gcc/testsuite/gfortran.dg/
	* dec_loc_rval_1.f90: New test.
        * dec_loc_rval_2.f90: New test.
        * dec_loc_rval_3.f90: New test.

From-SVN: r241519
parent 90051c26
2016-10-25 Fritz Reese <fritzoreese@gmail.com> 2016-10-25 Fritz Reese <fritzoreese@gmail.com>
* primary.c (gfc_match_rvalue): Match %LOC as LOC with -std=legacy.
* gfortran.texi: Document.
2016-10-25 Fritz Reese <fritzoreese@gmail.com>
* decl.c (gfc_match_type): New function. * decl.c (gfc_match_type): New function.
* match.h (gfc_match_type): New function. * match.h (gfc_match_type): New function.
* match.c (gfc_match_if): Special case for one-line IFs. * match.c (gfc_match_if): Special case for one-line IFs.
......
...@@ -1467,6 +1467,7 @@ compatibility extensions along with those enabled by @option{-std=legacy}. ...@@ -1467,6 +1467,7 @@ compatibility extensions along with those enabled by @option{-std=legacy}.
* Extended math intrinsics:: * Extended math intrinsics::
* Form feed as whitespace:: * Form feed as whitespace::
* TYPE as an alias for PRINT:: * TYPE as an alias for PRINT::
* %LOC as an rvalue::
@end menu @end menu
@node Old-style kind specifications @node Old-style kind specifications
...@@ -2537,6 +2538,26 @@ TYPE *, 'hello world' ...@@ -2537,6 +2538,26 @@ TYPE *, 'hello world'
PRINT *, 'hello world' PRINT *, 'hello world'
@end smallexample @end smallexample
@node %LOC as an rvalue
@subsection %LOC as an rvalue
@cindex LOC
Normally @code{%LOC} is allowed only in parameter lists. However the intrinsic
function @code{LOC} does the same thing, and is usable as the right-hand-side of
assignments. For compatibility, GNU Fortran supports the use of @code{%LOC} as
an alias for the builtin @code{LOC} with @option{-std=legacy}. With this
feature enabled the following two examples are equivalent:
@smallexample
integer :: i, l
l = %loc(i)
call sub(l)
@end smallexample
@smallexample
integer :: i
call sub(%loc(i))
@end smallexample
@node Extensions not implemented in GNU Fortran @node Extensions not implemented in GNU Fortran
@section Extensions not implemented in GNU Fortran @section Extensions not implemented in GNU Fortran
......
...@@ -2971,9 +2971,20 @@ gfc_match_rvalue (gfc_expr **result) ...@@ -2971,9 +2971,20 @@ gfc_match_rvalue (gfc_expr **result)
bool implicit_char; bool implicit_char;
gfc_ref *ref; gfc_ref *ref;
m = gfc_match_name (name); m = gfc_match ("%%loc");
if (m != MATCH_YES) if (m == MATCH_YES)
return m; {
if (!gfc_notify_std (GFC_STD_LEGACY, "%%LOC() as an rvalue at %C"))
return MATCH_ERROR;
strncpy (name, "loc", 4);
}
else
{
m = gfc_match_name (name);
if (m != MATCH_YES)
return m;
}
/* Check if the symbol exists. */ /* Check if the symbol exists. */
if (gfc_find_sym_tree (name, NULL, 1, &symtree)) if (gfc_find_sym_tree (name, NULL, 1, &symtree))
......
2016-10-25 Fritz Reese <fritzoreese@gmail.com> 2016-10-25 Fritz Reese <fritzoreese@gmail.com>
* gfortran.dg/dec_loc_rval_1.f90: New test.
* gfortran.dg/dec_loc_rval_2.f90: New test.
* gfortran.dg/dec_loc_rval_3.f90: New test.
2016-10-25 Fritz Reese <fritzoreese@gmail.com>
* gfortran.dg/dec_type_print.f90: New testcase. * gfortran.dg/dec_type_print.f90: New testcase.
2016-10-25 Fritz Reese <fritzoreese@gmail.com> 2016-10-25 Fritz Reese <fritzoreese@gmail.com>
......
! { dg-do run }
! { dg-options "-std=legacy" }
!
! Test the usage of %loc as an rvalue.
!
program main
implicit none
integer :: i, j, k
i = loc(j)
k = %loc(j)
if (i .ne. k) then
print *, "bad %loc value"
call abort()
endif
end
! { dg-do compile }
! { dg-options "-std=gnu" }
!
! Test warnings for usage of %loc as an rvalue without -std=legacy.
!
program main
implicit none
integer, volatile :: i, j, k
i = loc(j)
k = %loc(j) ! { dg-warning "Legacy Extension:" }
end
! { dg-do compile }
! { dg-options "-std=f2003" }
!
! Test errors for usage of %loc as an rvalue with a real standard.
!
program main
implicit none
integer, volatile :: i, j, k
k = %loc(j) ! { dg-error "Legacy Extension:" }
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment