===================================================================
@@ -7761,7 +7761,7 @@ resolve_select (gfc_code *code, bool select_type)
/* Strip all other unreachable cases. */
if (body->ext.block.case_list)
{
- for (cp = body->ext.block.case_list; cp->next; cp = cp->next)
+ for (cp = body->ext.block.case_list; cp && cp->next; cp = cp->next)
{
if (cp->next->unreachable)
{
===================================================================
@@ -0,0 +1,17 @@
+! { dg-do compile }
+! { dg-options -Wsurprising }
+
+ PROGRAM PR62135
+ IMPLICIT NONE
+ CHARACTER*1 :: choice
+ choice = 'x'
+ SELECT CASE (choice)
+ ! This triggered an ICE: an unreachable case clause
+ ! as the last of a list.
+ CASE ('2':'7','9':'0') ! { dg-warning "can never be matched" }
+ WRITE(*,*) "barf"
+ CASE DEFAULT
+ CONTINUE
+ END SELECT
+ END PROGRAM PR62135
+