From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by sourceware.org (Postfix) with ESMTPS id 68E573858D35 for ; Thu, 23 Nov 2023 20:03:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 68E573858D35 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 68E573858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::82a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700769821; cv=none; b=h4Ahv6R/9f8A5lXorQSlT8TavO8R1Um574dtc7tXKmqhftqfvHpsV6e6TS5XAXRrFD2piSkwMT2wiwBNSSBRnasO7uCAt1uKl8d5BZvo8biz35ExPy0VR2rSsCWPYnzc3GbcwD8tjppkmyNZu1liqIXP3xuMqqRPFmIoUP9uUjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700769821; c=relaxed/simple; bh=HU3rnnSDkTguCu13QUVSvhMCQRg6RzKWYMhnXNS0/AQ=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=orLqMshzuepW+E8P7hPVR6E4DacWwQhr/rhQNvNt72rqBmSxAabQIPotnllFwh+cKNZGD338klVf9BtVHimtaMpapAqgJYTzfA6FnJq4oXIWcgWbbGRJssSH7+gSE9BIKHt/4MzkfhIzWxIuRNLqlLWV9DxLkfbSxmRVkwslEW8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qt1-x82a.google.com with SMTP id d75a77b69052e-4237346c6efso5831241cf.0 for ; Thu, 23 Nov 2023 12:03:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700769818; x=1701374618; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=JV9FW3c4QC+o3deSO6LdnxvueCuffNr3WuKRwWVbjYo=; b=HwfuXJyT4CMPyNVkWLaoRVIaF6x9sVeTs278r//DEWyyhsmZxiijuOo91YxRNZOBM7 HCTt7F7BbEx1rEOZYf4XFnZz52Twqj9bMX4yfql6PyjLn4Hde6t4BDsm3vPvIg6f2Hap 1DtRyXJvgvKU+frYwaiYaMs3Y/Wx8DnSK+2v/gz4XXZ072RjplREk0cjGdEhHGtcUtmQ UP5PxqMvue1sOAzzx0Zj+tqXO4xGQv5IJoN+jYCu/4iEnXYwXBdrMywXlVHDJgt3YqUz recMF3Q7zfJIPPgajWo1XQ4TuKGnZtr2ub2PK7PM//sHRPs9gCCh0cAhDFOeAyxE6hRI X17A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700769818; x=1701374618; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JV9FW3c4QC+o3deSO6LdnxvueCuffNr3WuKRwWVbjYo=; b=BG20+HT4ilZUxA/KMyyoJem78OmnbiHrTp1Ifum9AriNzI00O55BDWGNswQBWPrCPr FKn/NNxHxguE7pIJV5qJrEdDRn1LtBV1hTjDohqkeI6fz7UP5yvkCqB6a4NdZFGjyhoe r4A0wFY0Wfi2604ZgxOsHOcXTeLrtbSmYJqVEhfKFDTimsdH9tHRhcwCJ5Qq5jc/uGZs 63me4Br9EJ3cjxZ+R897TCHvVNfZ8oNeGNVzu+D+wlF5Ltx3p1GLVRv7hnD8FMDpl5bj /rLj/j0IucoSHzAe3VTLGI4FDp9/qd+yl/ZYqLEY7rPTFycQ7z3oLu4oGwfyXq/HCEa6 NMmg== X-Gm-Message-State: AOJu0YzAq8oBG42dALer6bjooJ+vWToa9Lpy9IEUqhImeKpwEGzLdqI6 1D3QVqNCCrrQc3PX/ZJF8sw= X-Google-Smtp-Source: AGHT+IGug5qY4fq/B09IK+mhbOVzWaewHhgZ2qkGXccEWsNNHtuzplzBt/1cl/Oe+WOYM4Z2o4O1LA== X-Received: by 2002:ac8:5a11:0:b0:412:1e0a:772a with SMTP id n17-20020ac85a11000000b004121e0a772amr566626qta.17.1700769818532; Thu, 23 Nov 2023 12:03:38 -0800 (PST) Received: from ?IPV6:2601:19c:5282:9160::4? ([2601:19c:5282:9160::4]) by smtp.googlemail.com with ESMTPSA id x13-20020ac86b4d000000b00418122186ccsm707162qts.12.2023.11.23.12.03.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Nov 2023 12:03:37 -0800 (PST) Sender: Nathan Sidwell Message-ID: Date: Thu, 23 Nov 2023 15:03:37 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: Check module attachment instead of purview when necessary [PR112631] Content-Language: en-US To: Nathaniel Shead , gcc-patches@gcc.gnu.org Cc: Jason Merrill References: <655b2b3f.a70a0220.ca3c4.d564@mx.google.com> From: Nathan Sidwell In-Reply-To: <655b2b3f.a70a0220.ca3c4.d564@mx.google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3038.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,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 List-Id: On 11/20/23 04:47, Nathaniel Shead wrote: > 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. Ah I'd been puzzling over the default inlinedness of member-fns of block-scope structs. Could you augment the testcase to make sure that's right too? Something like: // dg-module-do link export module Mod; export auto Get () { struct X { void Fn () {} }; return X(); } /// import Mod void Frob () { Get().Fn(); } > > 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" } > +} -- Nathan Sidwell