public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-6100] Fortran: CASE selector expressions must be scalar Date: Wed, 22 Dec 2021 19:09:07 +0000 (GMT) [thread overview] Message-ID: <20211222190908.030E53858D35@sourceware.org> (raw) https://gcc.gnu.org/g:5474092c9afbd76cbd457facce3757d8d2fad07b commit r12-6100-g5474092c9afbd76cbd457facce3757d8d2fad07b Author: Harald Anlauf <anlauf@gmx.de> Date: Mon Dec 20 22:01:05 2021 +0100 Fortran: CASE selector expressions must be scalar gcc/fortran/ChangeLog: PR fortran/103776 * match.c (match_case_selector): Reject expressions in CASE selector which are not scalar. gcc/testsuite/ChangeLog: PR fortran/103776 * gfortran.dg/select_10.f90: New test. Diff: --- gcc/fortran/match.c | 13 +++++++++++++ gcc/testsuite/gfortran.dg/select_10.f90 | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index 52bc5af7542..617fb35c9cd 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -6088,6 +6088,19 @@ match_case_selector (gfc_case **cp) } } + if (c->low && c->low->rank != 0) + { + gfc_error ("Expression in CASE selector at %L must be scalar", + &c->low->where); + goto cleanup; + } + if (c->high && c->high->rank != 0) + { + gfc_error ("Expression in CASE selector at %L must be scalar", + &c->high->where); + goto cleanup; + } + *cp = c; return MATCH_YES; diff --git a/gcc/testsuite/gfortran.dg/select_10.f90 b/gcc/testsuite/gfortran.dg/select_10.f90 new file mode 100644 index 00000000000..2d9b0170ce9 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/select_10.f90 @@ -0,0 +1,25 @@ +! { dg-do compile } +! PR fortran/103776 - ICE in gfc_compare_string +! Contributed by G.Steinmetz + +program p + integer :: n + select case (n) + case ([1]) ! { dg-error "must be scalar" } + end select + select case (n) + case (:[2]) ! { dg-error "must be scalar" } + end select + select case (n) + case (['1']) ! { dg-error "must be scalar" } + end select + select case (n) + case (['1']:2) ! { dg-error "must be scalar" } + end select + select case (n) + case(['1']:['2']) ! { dg-error "must be scalar" } + end select + select case (n) + case(1:['2']) ! { dg-error "must be scalar" } + end select +end
reply other threads:[~2021-12-22 19:09 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211222190908.030E53858D35@sourceware.org \ --to=anlauf@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).