if (e->expr_type == EXPR_VARIABLE
&& e->symtree->n.sym->attr.intent == INTENT_IN
&& (gfc_current_intrinsic_arg[n]->intent == INTENT_OUT
- || gfc_current_intrinsic_arg[n]->intent == INTENT_INOUT))
+ || gfc_current_intrinsic_arg[n]->intent == INTENT_INOUT)
+ && !gfc_check_vardef_context (e, false, true, false, NULL))
{
- gfc_ref *ref;
- bool pointer = e->symtree->n.sym->ts.type == BT_CLASS
- && CLASS_DATA (e->symtree->n.sym)
- ? CLASS_DATA (e->symtree->n.sym)->attr.class_pointer
- : e->symtree->n.sym->attr.pointer;
-
- for (ref = e->ref; ref; ref = ref->next)
- {
- if (pointer && ref->type == REF_COMPONENT)
- break;
- if (ref->type == REF_COMPONENT
- && ((ref->u.c.component->ts.type == BT_CLASS
- && CLASS_DATA (ref->u.c.component)->attr.class_pointer)
- || (ref->u.c.component->ts.type != BT_CLASS
- && ref->u.c.component->attr.pointer)))
- break;
- }
-
- if (!ref)
- {
- gfc_error ("%qs argument of %qs intrinsic at %L cannot be "
- "INTENT(IN)", gfc_current_intrinsic_arg[n]->name,
- gfc_current_intrinsic, &e->where);
- return false;
- }
+ gfc_error ("%qs argument of %qs intrinsic at %L cannot be INTENT(IN)",
+ gfc_current_intrinsic_arg[n]->name,
+ gfc_current_intrinsic, &e->where);
+ return false;
}
if (e->expr_type == EXPR_VARIABLE
{
if (ptr_component && ref->type == REF_COMPONENT)
check_intentin = false;
- if (ref->type == REF_COMPONENT && ref->u.c.component->attr.pointer)
+ if (ref->type == REF_COMPONENT)
{
- ptr_component = true;
- if (!pointer)
+ gfc_component *comp = ref->u.c.component;
+ ptr_component = (comp->ts.type == BT_CLASS && comp->attr.class_ok)
+ ? CLASS_DATA (comp)->attr.class_pointer
+ : comp->attr.pointer;
+ if (ptr_component && !pointer)
check_intentin = false;
}
if (ref->type == REF_INQUIRY
integer, allocatable :: a
type(t2), pointer :: ta
- call move_alloc (px, ta) ! { dg-error "cannot be INTENT.IN." }
+ call move_alloc (px, ta) ! { dg-error "must be ALLOCATABLE" }
call move_alloc (x%a, a) ! { dg-error "cannot be INTENT.IN." }
call move_alloc (x%ptr%a, a) ! OK (3)
call move_alloc (px%a, a) ! OK (4)
integer, allocatable :: a
class(t2), pointer :: ta
- call move_alloc (px, ta) ! { dg-error "cannot be INTENT.IN." }
+ call move_alloc (px, ta) ! { dg-error "must be ALLOCATABLE" }
call move_alloc (x%a, a) ! { dg-error "cannot be INTENT.IN." }
call move_alloc (x%ptr%a, a) ! OK (6)
call move_alloc (px%a, a) ! OK (7)
--- /dev/null
+! { dg-do compile }
+! PR fortran/103418
+! Validate checks for dummy arguments with INTENT(IN), pointer attribute
+
+module m
+ type t
+ real, pointer :: a, b(:)
+ end type t
+contains
+ subroutine s1 (a, b, c, d, e)
+ real, pointer, intent(in) :: a, b(:)
+ type(t), intent(in) :: c
+ class(t), intent(in) :: d
+ type(t), pointer, intent(in) :: e
+ real, pointer :: pa, pb(:)
+ call random_number (a) ! legal
+ call random_number (b)
+ call cpu_time (a)
+ call system_clock (count_rate=a)
+ call random_number (c% a)
+ call random_number (c% b)
+ call random_number (d% a)
+ call random_number (d% b)
+ call random_number (e% a)
+ call random_number (e% b)
+ call move_alloc (a, pa) ! { dg-error "must be ALLOCATABLE" }
+ call move_alloc (b, pb) ! { dg-error "must be ALLOCATABLE" }
+ allocate (a) ! { dg-error "pointer association context" }
+ allocate (b(10)) ! { dg-error "pointer association context" }
+ allocate (c% a) ! { dg-error "pointer association context" }
+ allocate (c% b(10)) ! { dg-error "pointer association context" }
+ end subroutine s1
+end module