From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id EDBC73858D28; Sat, 28 Jan 2023 20:58:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EDBC73858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674939499; bh=p0LfvAUbzQabK39Q77pZ8gAfx1hA9JUuPVa1lacRXmQ=; h=From:To:Subject:Date:From; b=KsT3PswnmnIlRWMx12izauMZ972zsXda8Tjjgm0dBJRvSG5eYSFPKzOZfI8yqZKTM pbJC5+OeEni0dXp6yr37jtFijxjKoZcAaU1nCFz3Xa40qGHjCAsekbNh4lYocfwdXy Ojfr2+FedUDvisVV6TY/OV30x57dfyvp+AGsntO8= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Harald Anlauf To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5478] Fortran: diagnose USE associated symbols in COMMON blocks [PR108453] X-Act-Checkin: gcc X-Git-Author: Harald Anlauf X-Git-Refname: refs/heads/master X-Git-Oldrev: 679f75167b1294fe6c3a281fe5bbafc734777407 X-Git-Newrev: aba9ff8f30d4245294ea2583de1dc28f1c7ccf7b Message-Id: <20230128205819.EDBC73858D28@sourceware.org> Date: Sat, 28 Jan 2023 20:58:19 +0000 (GMT) List-Id: https://gcc.gnu.org/g:aba9ff8f30d4245294ea2583de1dc28f1c7ccf7b commit r13-5478-gaba9ff8f30d4245294ea2583de1dc28f1c7ccf7b Author: Harald Anlauf Date: Sat Jan 28 17:59:23 2023 +0100 Fortran: diagnose USE associated symbols in COMMON blocks [PR108453] gcc/fortran/ChangeLog: PR fortran/108453 * match.cc (gfc_match_common): A USE associated name shall not appear in a COMMON block (F2018:C8121). gcc/testsuite/ChangeLog: PR fortran/108453 * gfortran.dg/common_27.f90: New test. Diff: --- gcc/fortran/match.cc | 10 ++++++++++ gcc/testsuite/gfortran.dg/common_27.f90 | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/gcc/fortran/match.cc b/gcc/fortran/match.cc index 5e933c12931..5eb6d0e1c1d 100644 --- a/gcc/fortran/match.cc +++ b/gcc/fortran/match.cc @@ -5345,6 +5345,16 @@ gfc_match_common (void) goto cleanup; } + /* F2018:R874: common-block-object is variable-name [ (array-spec) ] + F2018:C8121: A variable-name shall not be a name made accessible + by use association. */ + if (sym->attr.use_assoc) + { + gfc_error ("Symbol %qs at %C is USE associated from module %qs " + "and cannot occur in COMMON", sym->name, sym->module); + goto cleanup; + } + /* Deal with an optional array specification after the symbol name. */ m = gfc_match_array_spec (&as, true, true); diff --git a/gcc/testsuite/gfortran.dg/common_27.f90 b/gcc/testsuite/gfortran.dg/common_27.f90 new file mode 100644 index 00000000000..dcde5de2bd2 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/common_27.f90 @@ -0,0 +1,14 @@ +! { dg-do compile } +! PR fortran/108453 - a use associated variable cannot occur in COMMON +! Contributed by G.Steinmetz + +module m + type t + end type + real :: r +end +program p + use m, only: t, r + common t ! { dg-error "USE associated from module" } + common /cm/ r ! { dg-error "USE associated from module" } +end