From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id 79D803858C52; Sat, 4 Feb 2023 15:43:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 79D803858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675525386; bh=ozp80knjq8RX6A74CB0DOtT6iqgZOOMtBNtkPwMmEes=; h=From:To:Subject:Date:From; b=N62AB7GwTFncPqRf4eEtORh5OIX9SLFBtAEf11lz1dFbTMwOH5nnaQRU++BDER4eB 3uQDr4KX5v4A6J63W1mpDdPmWzITRepl/OGeNaX7eVg3Sffl70wqAezgDMbODpcFn2 I+0vVvMxzFllywpcb1jNWLrNei7JuZTnYdFgwFSo= 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 r11-10500] Fortran: diagnose USE associated symbols in COMMON blocks [PR108453] X-Act-Checkin: gcc X-Git-Author: Harald Anlauf X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 49c2e56064b2b3500681010dfff1698b375fc515 X-Git-Newrev: be8003ffcfb02dd8ef49ffec01bf96da2d973bc2 Message-Id: <20230204154306.79D803858C52@sourceware.org> Date: Sat, 4 Feb 2023 15:43:06 +0000 (GMT) List-Id: https://gcc.gnu.org/g:be8003ffcfb02dd8ef49ffec01bf96da2d973bc2 commit r11-10500-gbe8003ffcfb02dd8ef49ffec01bf96da2d973bc2 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.c (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. (cherry picked from commit aba9ff8f30d4245294ea2583de1dc28f1c7ccf7b) Diff: --- gcc/fortran/match.c | 10 ++++++++++ gcc/testsuite/gfortran.dg/common_27.f90 | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index 860b6567d2a..91b31e06e56 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -5299,6 +5299,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