2010-10-20 Tobias Burnus <burnus@net-b.de>
PR fortran/46100
* expr.c (gfc_check_vardef_context): Treat pointer functions
as variables.
2010-10-20 Tobias Burnus <burnus@net-b.de>
PR fortran/46100
* gfortran.dg/ptr-func-1.f90: New.
* gfortran.dg/ptr-func-2.f90: New.
@@ -4316,7 +4316,18 @@ gfc_check_vardef_context (gfc_expr* e, bool pointer, const char* context)
symbol_attribute attr;
gfc_ref* ref;
- if (e->expr_type != EXPR_VARIABLE)
+ if (!pointer && e->expr_type == EXPR_FUNCTION
+ && e->symtree->n.sym->result->attr.pointer)
+ {
+ if (!(gfc_option.allow_std & GFC_STD_F2008))
+ {
+ if (context)
+ gfc_error ("Fortran 2008: Pointer functions in variable definition"
+ " context (%s) at %L", context, &e->where);
+ return FAILURE;
+ }
+ }
+ else if (e->expr_type != EXPR_VARIABLE)
{
if (context)
gfc_error ("Non-variable expression in variable definition context (%s)"
new file mode 100644
@@ -0,0 +1,24 @@
+! { dg-do compile }
+! { dg-options "-std=f2008 -fall-intrinsics" }
+!
+! PR fortran/46100
+!
+! Pointer function as definable actual argument
+! - a Fortran 2008 feature
+!
+integer, target :: tgt
+call one (two ())
+if (tgt /= 774) call abort ()
+contains
+ subroutine one (x)
+ integer, intent(inout) :: x
+ if (x /= 34) call abort ()
+ x = 774
+ end subroutine one
+ function two ()
+ integer, pointer :: two
+ two => tgt
+ two = 34
+ end function two
+end
+
new file mode 100644
@@ -0,0 +1,24 @@
+! { dg-do compile }
+! { dg-options "-std=f2003 -fall-intrinsics" }
+!
+! PR fortran/46100
+!
+! Pointer function as definable actual argument
+! - a Fortran 2008 feature
+!
+integer, target :: tgt
+call one (two ()) ! { dg-error "Fortran 2008: Pointer functions" }
+if (tgt /= 774) call abort ()
+contains
+ subroutine one (x)
+ integer, intent(inout) :: x
+ if (x /= 34) call abort ()
+ x = 774
+ end subroutine one
+ function two ()
+ integer, pointer :: two
+ two => tgt
+ two = 34
+ end function two
+end
+