diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index c8301f659b7..16ed9e9d68b 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,11 @@ +2008-09-25 Tobias Burnus + + PR fortran/37504 + * expr.c (gfc_check_pointer_assign): Allow assignment of + protected pointers. + * match.c (gfc_match_assignment,gfc_match_pointer_assignment): + Remove unreachable code. + 2008-09-24 Tobias Burnus * options.c (set_default_std_flags,gfc_init_options): diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index e15412adfbe..7b741b88050 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -3076,7 +3076,8 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr *rvalue) return FAILURE; } - if (attr.is_protected && attr.use_assoc) + if (attr.is_protected && attr.use_assoc + && !(attr.pointer || attr.proc_pointer)) { gfc_error ("Pointer assignment target has PROTECTED " "attribute at %L", &rvalue->where); diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index f7ff9bbdc3b..c8fd30d754f 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -1293,15 +1293,6 @@ gfc_match_assignment (void) return MATCH_NO; } - if (lvalue->symtree->n.sym->attr.is_protected - && lvalue->symtree->n.sym->attr.use_assoc) - { - gfc_current_locus = old_loc; - gfc_free_expr (lvalue); - gfc_error ("Setting value of PROTECTED variable at %C"); - return MATCH_ERROR; - } - rvalue = NULL; m = gfc_match (" %e%t", &rvalue); if (m != MATCH_YES) @@ -1353,14 +1344,6 @@ gfc_match_pointer_assignment (void) if (m != MATCH_YES) goto cleanup; - if (lvalue->symtree->n.sym->attr.is_protected - && lvalue->symtree->n.sym->attr.use_assoc) - { - gfc_error ("Assigning to a PROTECTED pointer at %C"); - m = MATCH_ERROR; - goto cleanup; - } - new_st.op = EXEC_POINTER_ASSIGN; new_st.expr = lvalue; new_st.expr2 = rvalue; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0be7f7da658..2941ac9778c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-09-25 Tobias Burnus + + PR fortran/37504 + * gfortran.dg/protected_7.f90: New test. + 2008-09-24 Steve Ellcey * gcc.dg/vect/O3-vect-pr34223.c: Check vect_int_mult. diff --git a/gcc/testsuite/gfortran.dg/protected_7.f90 b/gcc/testsuite/gfortran.dg/protected_7.f90 new file mode 100644 index 00000000000..0325a49a568 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/protected_7.f90 @@ -0,0 +1,22 @@ +! { dg-do compile } +! PR fortran/37504 +! +module m + implicit none + integer, pointer, protected :: protected_pointer + integer, target, protected :: protected_target +end module m + +program p + use m + implicit none + integer, pointer :: unprotected_pointer + ! The next two lines should be rejected; see PR 37513 why + ! we get such a strange error message. + protected_pointer => unprotected_pointer ! { dg-error "only allowed in specification part" } + protected_pointer = unprotected_pointer ! { dg-error "only allowed in specification part" } + unprotected_pointer => protected_target ! { dg-error "target has PROTECTED attribute" } + unprotected_pointer => protected_pointer ! OK +end program p + +! { dg-final { cleanup-modules "m" } }