Patch is self-explanatory. Built and regression tested on x86_64-*-freebsd. OK to commit?
2015-09-21 Steven G. Kargl <ka...@gcc.gnu.org> PR fortran/67615 * resolve.c (gfc_resolve_code): Check for scalar expression in arithmetic-if. 2015-09-21 Steven G. Kargl <ka...@gcc.gnu.org> PR fortran/67615 * gfortran.dg/pr67615.f90: new test. -- Steve
Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (revision 227976) +++ gcc/fortran/resolve.c (working copy) @@ -10377,15 +10381,18 @@ gfc_resolve_code (gfc_code *code, gfc_na } case EXEC_ARITHMETIC_IF: - if (t - && code->expr1->ts.type != BT_INTEGER - && code->expr1->ts.type != BT_REAL) - gfc_error ("Arithmetic IF statement at %L requires a numeric " - "expression", &code->expr1->where); + { + gfc_expr *e = code->expr1; - resolve_branch (code->label1, code); - resolve_branch (code->label2, code); - resolve_branch (code->label3, code); + if (t && (e->rank > 0 + || !(e->ts.type == BT_REAL || e->ts.type == BT_INTEGER))) + gfc_error ("Arithmetic IF statement at %L requires a scalar " + "REAL or INTEGER expression", &code->expr1->where); + + resolve_branch (code->label1, code); + resolve_branch (code->label2, code); + resolve_branch (code->label3, code); + } break; case EXEC_IF: Index: gcc/testsuite/gfortran.dg/pr67615.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr67615.f90 (revision 0) +++ gcc/testsuite/gfortran.dg/pr67615.f90 (working copy) @@ -0,0 +1,33 @@ +! { dg-do compile } +! { dg-options "-std=legacy" } +! PR fortran/67615 +! +program foo + + implicit none + + integer i(2), j + real x + complex z + + j = 2 + if (j) 10, 20, 30 + + x = -1 + if (x) 10, 20, 30 + + z = (1,2) + if (z) 10, 20, 30 ! { dg-error "Arithmetic IF statement" } + + i = [1, 2] + if (i) 10, 20, 30 ! { dg-error "Arithmetic IF statement" } + + if ( [1] ) 10, 20, 30 ! { dg-error "Arithmetic IF statement" } + if ( [1, -1] ) 10, 20, 30 ! { dg-error "Arithmetic IF statement" } + if ( [real :: 1, -1] ) 10, 20, 30 ! { dg-error "Arithmetic IF statement" } + +10 stop +20 stop +30 stop + +end program foo