From patchwork Tue Aug 13 17:25:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1972044 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=anlauf@gmx.de header.a=rsa-sha256 header.s=s31663417 header.b=PN7UmRNX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wjyvd2pYCz1yYl for ; Wed, 14 Aug 2024 03:25:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A086D385C6CC for ; Tue, 13 Aug 2024 17:25:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by sourceware.org (Postfix) with ESMTPS id 955DE3858417; Tue, 13 Aug 2024 17:25:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 955DE3858417 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 955DE3858417 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.15.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723569907; cv=none; b=xkLhmJMgT7x9BQrL8Iijst7OwLDKo4fp96ymWkQBPXlxLu4MBBQzxoLkFHAeuNSiYfRLji377mFnfa6n0cDMyccqr5EvHRqxtKLUJfcKiMMq7re2B4QUbu0xMyjgFVROieiNrfLM1HPqWDYeJWvR5blNHzNGJoB6EmB+Pd1JULM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723569907; c=relaxed/simple; bh=IG/cFQB6UnpcxI3TR036TwHxIIrRZr26se83xayzhc0=; h=DKIM-Signature:MIME-Version:Message-ID:From:To:Subject:Date; b=w6I77OoNogJ0V0M31nO79AydlZstBGtJ3wEZJr8nBgD/pbyOR/vhIDHSx+5irfLVdG6CnRz07uIDVHv95M11pgXZYTMjixPErJdqTuQXkih4kbVysk3jOrbzpU4dTFM2Qm3VmBLgUldo5fsyE19bK9nTeQjLNw28X0BhZL3dZWg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1723569904; x=1724174704; i=anlauf@gmx.de; bh=k884JamSUgH/hK/Tt/aPCUM63l8qUd0LJVSEEIe2fyw=; h=X-UI-Sender-Class:MIME-Version:Message-ID:From:To:Subject: Content-Type:Date:cc:content-transfer-encoding:content-type:date: from:message-id:mime-version:reply-to:subject:to; b=PN7UmRNXT0ac53rT9G/T0RW9zyYTildfETFVfWSm8/iHsDdIbAMuNEgg5pwwqMOs v08Fh24C2uYt/zAt96KYW8cqgUjlLufZeudYQts+gXpP7yDq0aMUA/bM1p36B6AQ7 5tPB7xuoFhAtK01mZeLiM0SajuI5/qunKpp9GHcncnTeuTC2jjsMNhZHKFzwe5ovu ogC/lNfbk0pHQlKCsF63A1waoHaTpVOQS4M0Svd5xpsZnC4CWGtiAshgvCF7g2yPn U4xQvPImvycN50WMeqvA3CYrU65UwmuwZeSd6OB9FlXcxOnSoJTYm/Td98r+7ciZ8 7NnvGqz2wz+seIOg4Q== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.82.89] ([93.207.82.89]) by web-mail.gmx.net (3c-app-gmx-bs39.server.lan [172.19.170.91]) (via HTTP); Tue, 13 Aug 2024 19:25:04 +0200 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: reject array constructor value of abstract type [PR114308] Date: Tue, 13 Aug 2024 19:25:04 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:BbzTg266GzdR1tIlj+59uyUvWOAVQ2zjIWMoV17MmbMaR611zbB82Feag634PQUsZqvUf CzvkgSy+K0Vq8yjTN2XHh/CsE2XCjuSfMQiaqoMyJnbG1tFKntaFymBs4y/yuhSSKpMGbMf2oVRM rAW8Pp2PNwUSa4IJ669O+sHTEBMMZY5/Qx52yIeydPWb68j14L2BrKUKeb9Rv/QQAvCD7ra1DiGV ucWTyQtioCYcPqtV8xWzD4Dm0BWU2k5Cpl8IG6WSxLfDvKEe1EZ7xJ89RKI+x67aFJ8dMw3QzUgT qc= UI-OutboundReport: notjunk:1;M01:P0:vwPVSrs9P8k=;QsB8/dkGjD1KhafRkcLlAmXDaVv rg76SDXK+B7t66OOJM6urtlW2/T3P5Ss9j5KjDLX1TuJXNUc7v7lqodKO7+eiLS+0alo46sB8 lyMt83k6S/T1QFNEIPQkZp6P+uklQGFNPTqf42TZGm3oe0aI4067+lL857w9SO4wypGDnT1/k 4ZLIjju0K3WV1Z577igaFmuAc+zPr9BOWS2OqA2cA02tcGbPoA08NymnPUmB5ruDaQkCeTAPj fvjV4RO7xFiZMy96vXDY4YDuWoPeRYYE3zcnyEfHB10kGXlnjx70MTzAnVXT63qJFcoSR4Orz 91CiLIRF78u+lUKfrVSARSjw+rHb3QrDb5cMAoSZXpWPAEhoE095UZDOxzjA7SnPLK26GBxGR VsSCzaLlXbDTVP39ecYlgevqqQcN5ePC1PS/S/3SDIT7JeN7fBXFUiISwUm1Hydm71GWlmOoK zekAKXDuv956rdf+rHq72V3X++922abflWTEptfdU7YichzicItmSSpOuPzLb+AmMDfkY7Jdk S5X5DCMURLwDbKKAljs+0VV8d/Lj26YxksSXHXWfB5y3qFEOQRRjnw9OZ6+h7a49PtQ6DT1l8 D3KrS1uAvsmWaAKE5iS1PSn5lfq6RMsuW6kbZqx4H5XUi418wOxdoZ7nQzca34YxsUD35QgEH EDvblhTWg4oDejpILwUjfrVPUyM7yad+SAgM/sKKJA== X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Dear all, the attached patch checks whether the declared type of an array constructor value is abstract, which is forbidden by the standard. Steve found the relevant constraint in F2023, but it exists already in F2018. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From 9988d7e004796ab531df7bcda45788a7aa9276d7 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Tue, 13 Aug 2024 19:17:36 +0200 Subject: [PATCH] Fortran: reject array constructor value of abstract type [PR114308] gcc/fortran/ChangeLog: PR fortran/114308 * array.cc (resolve_array_list): Reject array constructor value if its declared type is abstract (F2018:C7114). gcc/testsuite/ChangeLog: PR fortran/114308 * gfortran.dg/abstract_type_10.f90: New test. Co-Authored-By: Steven G. Kargl --- gcc/fortran/array.cc | 13 ++++++++ .../gfortran.dg/abstract_type_10.f90 | 30 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/abstract_type_10.f90 diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc index 79c774d59a0..a5e94f1fa77 100644 --- a/gcc/fortran/array.cc +++ b/gcc/fortran/array.cc @@ -2127,6 +2127,19 @@ resolve_array_list (gfc_constructor_base base) "polymorphic [F2008: C4106]", &c->expr->where); t = false; } + + /* F2018:C7114 The declared type of an ac-value shall not be abstract. */ + if (c->expr->ts.type == BT_CLASS + && c->expr->ts.u.derived + && c->expr->ts.u.derived->attr.abstract + && CLASS_DATA (c->expr)) + { + gfc_error ("Array constructor value %qs at %L is of the ABSTRACT " + "type %qs", c->expr->symtree->name, &c->expr->where, + CLASS_DATA (c->expr)->ts.u.derived->name); + t = false; + } + } return t; diff --git a/gcc/testsuite/gfortran.dg/abstract_type_10.f90 b/gcc/testsuite/gfortran.dg/abstract_type_10.f90 new file mode 100644 index 00000000000..a4bf65d4e12 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/abstract_type_10.f90 @@ -0,0 +1,30 @@ +! { dg-do compile } +! +! PR fortran/114308 - reject array constructor value of abstract type + +module my_module + implicit none + private + + type, abstract, public :: a + end type + + type, extends(a), public :: b + end type +end + +program main + use my_module + implicit none + type(b) :: b_instance + class(a), allocatable :: a_array(:) + class(b), allocatable :: b_array(:) + + a_array = [b_instance] + b_array = [b_instance] + a_array = [a_array] ! { dg-error "is of the ABSTRACT type" } + a_array = [a_array(1)] ! { dg-error "is of the ABSTRACT type" } + a_array = [a_array, b_instance] ! { dg-error "is of the ABSTRACT type" } + a_array = [b_instance, a_array] ! { dg-error "is of the ABSTRACT type" } + b_array = [b_array, a_array] ! { dg-error "is of the ABSTRACT type" } +end program -- 2.35.3