+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.
* Extended math intrinsics::
* Form feed as whitespace::
* TYPE as an alias for PRINT::
+* %LOC as an rvalue::
@end menu
@node Old-style kind specifications
PRINT *, 'hello world'
@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
@section Extensions not implemented in GNU Fortran
bool implicit_char;
gfc_ref *ref;
- m = gfc_match_name (name);
- if (m != MATCH_YES)
- return m;
+ m = gfc_match ("%%loc");
+ if (m == MATCH_YES)
+ {
+ 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. */
if (gfc_find_sym_tree (name, NULL, 1, &symtree))
+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.
--- /dev/null
+! { 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
--- /dev/null
+! { 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
--- /dev/null
+! { 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