+++ This bug was initially created as a clone of Bug #37504 +++ gfortran rightly rejects the following program, however, the error message is misleading:
PROTECTED at (1) only allowed in specification part of a module module m implicit none integer, pointer, protected :: protected_pointer end module m program p use m implicit none integer, pointer :: unprotected_pointer protected_pointer => unprotected_pointer end program p * * * The reason is as follows: decode_statement calls "gfc_match_pointer_assignment" which calls in turn match_variable, which calls "gfc_error ("Assigning to PROTECTED variable at %C");". However, as "gfc_match_pointer_assignment" does not return MATCH_YES, one proceeds in decode_statement and reaches gfc_match_protected, which also calls gfc_error. Only the last error message is printed, i.e. the one of gfc_match_protected. * * * My first attempt was to do an if(gfc_match_pointer_assignment() == MATCH_ERROR) goto error; however, that fails since gfc_match_pointer_assignment returns MATCH_NO and not MATCH_ERROR if match ("%v =>") fails. (It fails because of the "Assigning to PROTECTED variable at %C".) Removing the "m = MATCH_NO" in gfc_match_pointer_assignment works for this test case, but let's several test cases fail in the test suite. Note: The checks for PROTECTED in gfc_match_assignment and gfc_match_pointer_assignment are not needed as the match_variable() check comes first. * * * My next attempt was to remove the current checks from primary.c and match.c and insert them into gfc_check_assign / gfc_check_pointer_assign. However, that fails for e.g. protected_5.f90: I miss an error for "allocate(t%array(15))" but I get one for "use good2", which is not only the lexpr->where/rexpr->where, but also the case if "use good2" is the only statement in "program main". I fail to understand why this goes wrong. -- Summary: Wrongly rejects: unprotected_pointer => protected_pointer Product: gcc Version: 4.4.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: burnus at gcc dot gnu dot org BugsThisDependsOn: 37504 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37513