From patchwork Mon Nov 20 09:47:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1865913 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; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JuOnWArH; 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 4SYjP02Kccz1ySC for ; Mon, 20 Nov 2023 20:48:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B74D385C6E0 for ; Mon, 20 Nov 2023 09:47:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 7DAA23858C5F for ; Mon, 20 Nov 2023 09:47:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7DAA23858C5F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7DAA23858C5F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::431 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700473666; cv=none; b=A8RHGJxeAuOPuBsfeaSrg+IDfpbGrCUOpCnVG4u7q6rTgrJHDzRdyl3Km74qtvx49T7tXcBckn98qVU6e0gDMVMlsOp/mfzlSXVsdmggFXyZqGoWyG2qdk5WwdiAfb+z2qOFj9MjkvMNacWQRiTXmGjHQZxJ9UnEk5lculOGteQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700473666; c=relaxed/simple; bh=X5YiJPV3Y6INjmbNPJ+HHCa9eOlwrATFinnx0IjCfeo=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=sZdMmU19RV9/NQjJPVKHhlW+6rh3UR0XdJKhVUxEnA6VK1anliHp0r8cQgeK25jDU5mjbjz2iQCb1H7DkmsGRE+VYX/VhLfC9bDHqS7DJNej2vnqBhLanguhOEcPwaQTMBOqWNmzleqfyzgTyLjBW3UpMdVShv/Z3JJHre2GZyY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6c4d06b6ddaso3413337b3a.3 for ; Mon, 20 Nov 2023 01:47:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700473664; x=1701078464; darn=gcc.gnu.org; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Cw2MSRco3kSD7xeR8MS/TKAt28rvP776dfYLQIbNaZY=; b=JuOnWArH6eyG8NH+scr+Svg63Xwh40ZAOkGaMbjlJN4T4Jk/GWlKiIXpxJ99inVs59 lLRZfDUGoybuXGz6ZRMoLD2zdhN8eJg6bpNW2OzWtysQtC1b6dZrWLQPPgXidJIuHctT ZHAcN1HplAiq/D6747Bc3Be3Q3iel1HpPNE2tIVDSEUjszrx1WBfByBQHxkF/U+yU6Yv nR1Z8ezkqJE59X/VG+06GMQ/b1Ji75lE/leYTt5v/4CcTu1ed4Ddi1JaCgpq7nySX/CQ qKV3V6MAMjXFJl8D4R5y5KEOF83YjpjolzmprO32iXyEKMQ0CMJJbk9e/q/t4F1tLATF mUdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700473664; x=1701078464; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Cw2MSRco3kSD7xeR8MS/TKAt28rvP776dfYLQIbNaZY=; b=l3ozE/hnQ6uSt8DHcGSPXqeeba6Q10e1OAjfVJAwwPfuMAxA7OToXdZcXuU6QRWMrL HuKW6o28xUhlVrOcm3G1JHKhn+GrPctyOcJyJSoprZTO/NKcHvCUO8mcSUdHh+V4D0Em eghcOzyhl2/qau0IDoa8BN6BoAmXJDIcBW4v0REXrseFblaBi9HJTka50ZM3a04tiJ2b uHCK9XH0eQAQX1bsH+WNy8pD+UIw2F2hBhCM+UZgUfsPcyydlkKgWK8FUwvT/zAfSYsb RFm6eemJnDyOCtrvfCCZYtmFRBJZap0nqjRTDudecMBFI34pxJ5AoV+qlUs/Hntkvi1s iQbg== X-Gm-Message-State: AOJu0YyHNm+Zywn81US+q8H5TAOymARigBNZKtwK61TqM9ikiQbKl61m XMbfqu9JBWWy5CQUVCfhsLFvUzll+dM= X-Google-Smtp-Source: AGHT+IG+YzImh/BAb12gmCWBfnBLT0a1+NfjF9jw0p7oHsAhgyKXOfXnzXPpddrC2I2mtfa/HmECKQ== X-Received: by 2002:a05:6a00:2e82:b0:6bb:8982:411c with SMTP id fd2-20020a056a002e8200b006bb8982411cmr6166222pfb.8.1700473664185; Mon, 20 Nov 2023 01:47:44 -0800 (PST) Received: from Thaum. (124-150-88-161.tpgi.com.au. [124.150.88.161]) by smtp.gmail.com with ESMTPSA id x16-20020aa79a50000000b00690ca67d429sm5550482pfj.100.2023.11.20.01.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 01:47:43 -0800 (PST) Message-ID: <655b2b3f.a70a0220.ca3c4.d564@mx.google.com> X-Google-Original-Message-ID: Date: Mon, 20 Nov 2023 20:47:39 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH] c++: Check module attachment instead of purview when necessary [PR112631] MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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 Bootstrapped and regtested on x86_64-pc-linux-gnu. I don't have write access. -- >8 -- Block-scope declarations of functions or extern values are not allowed when attached to a named module. Similarly, class member functions are not inline if attached to a named module. However, in both these cases we currently only check if the declaration is within the module purview; it is possible for such a declaration to occur within the module purview but not be attached to a named module (e.g. in an 'extern "C++"' block). This patch makes the required adjustments. PR c++/112631 gcc/cp/ChangeLog: * cp-tree.h (named_module_attach_p): New function. * decl.cc (start_decl): Use named_module_attach_p instead of named_module_purview_p. (grokmethod): Likewise. gcc/testsuite/ChangeLog: * g++.dg/modules/pr112631.C: New test. --- gcc/cp/cp-tree.h | 2 ++ gcc/cp/decl.cc | 10 +++++----- gcc/testsuite/g++.dg/modules/pr112631.C | 8 ++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/pr112631.C diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 7b0b7c6a17e..9a3981cef58 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7315,6 +7315,8 @@ inline bool module_attach_p () inline bool named_module_purview_p () { return named_module_p () && module_purview_p (); } +inline bool named_module_attach_p () +{ return named_module_p () && module_attach_p (); } /* We're currently exporting declarations. */ inline bool module_exporting_p () diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index e6f75d771e0..395f108aec7 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -5917,10 +5917,10 @@ start_decl (const cp_declarator *declarator, { /* A function-scope decl of some namespace-scope decl. */ DECL_LOCAL_DECL_P (decl) = true; - if (named_module_purview_p ()) + if (named_module_attach_p ()) error_at (declarator->id_loc, - "block-scope extern declaration %q#D not permitted" - " in module purview", decl); + "block-scope extern declaration %q#D must not be" + " attached to a named module", decl); } /* Enter this declaration into the symbol table. Don't push the plain @@ -18513,10 +18513,10 @@ grokmethod (cp_decl_specifier_seq *declspecs, check_template_shadow (fndecl); /* p1779 ABI-Isolation makes inline not a default for in-class - definitions in named module purview. If the user explicitly + definitions attached to a named module. If the user explicitly made it inline, grokdeclarator will already have done the right things. */ - if ((!named_module_purview_p () + if ((!named_module_attach_p () || flag_module_implicit_inline /* Lambda's operator function remains inline. */ || LAMBDA_TYPE_P (DECL_CONTEXT (fndecl))) diff --git a/gcc/testsuite/g++.dg/modules/pr112631.C b/gcc/testsuite/g++.dg/modules/pr112631.C new file mode 100644 index 00000000000..b5e81a1041b --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr112631.C @@ -0,0 +1,8 @@ +// { dg-additional-options "-fmodules-ts" } +// { dg-module-cmi bla } + +export module bla; + +extern "C++" inline void fun() { + void oops(); // { dg-bogus "block-scope extern declaration" } +}