https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88248
--- Comment #6 from Harald Anlauf <anlauf at gmx dot de> --- Moving the check from gfc_define_st_label to gfc_reference_st_label: Index: symbol.c =================================================================== --- symbol.c (revision 268826) +++ symbol.c (working copy) @@ -2743,10 +2743,6 @@ "DO termination statement which is not END DO" " or CONTINUE with label %d at %C", labelno)) return; - if (type == ST_LABEL_DO_TARGET - && !gfc_notify_std (GFC_STD_F2018_OBS, "Labeled DO statement " - "at %L", label_locus)) - return; break; default: @@ -2804,6 +2800,11 @@ "Shared DO termination label %d at %C", labelno)) return false; + if (type == ST_LABEL_DO_TARGET + && !gfc_notify_std (GFC_STD_F2018_OBS, "Labeled DO statement " + "at %L", &gfc_current_locus)) + return false; + if (lp->referenced != ST_LABEL_DO_TARGET) lp->referenced = type; rc = true; fixes the issue for me. It consequently needs adjustment to the test case f2018_obs.f90, since it references the line with the "do 99 ..." instead of the do termination line. I am wondering about the location of the error marker. E.g. for subroutine gfcbug151 () do 99 i = 1, 10 99 continue end subroutine gfcbug151 I get: gfcbug151.f90:2:17: 2 | do 99 i = 1, 10 | 1 Warning: Fortran 2018 obsolescent feature: Labeled DO statement at (1) But I think this is ok. Should I submit the above, or are there better suggestions?