public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@acm.org>
To: Nathaniel Shead <nathanieloshead@gmail.com>, gcc-patches@gcc.gnu.org
Cc: Jason Merrill <jason@redhat.com>
Subject: Re: [PATCH] c++/modules: handle templates in exported using-declarations [PR106849]
Date: Thu, 9 Nov 2023 17:59:43 -0500	[thread overview]
Message-ID: <9cef0501-26d3-4bc2-a895-d9ee32648ca8@acm.org> (raw)
In-Reply-To: <654d49dd.620a0220.e2d42.d2a9@mx.google.com>

On 11/9/23 16:06, Nathaniel Shead wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu.
> 
> -- >8 --
> 
> A TEMPLATE_DECL does not have module attachment flags associated with
> it, so this patch extracts the result from the template to read the
> flags from there instead.
> 

oh yeah.  my original plan had it duplicated, but that didn't work out well. 
You can use
    tree decl = STRIP_TEMPLATE (new_fn);
btw.  ok with that change

> As a drive-by fix we also group the error with its informative note.
> 
> 	PR c++/106849
> 
> gcc/cp/ChangeLog:
> 
> 	* name-lookup.cc (do_nonmember_using_decl): Handle
> 	TEMPLATE_DECLs when checking module attachment.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/modules/using-9.C: New test.
> 
> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> ---
>   gcc/cp/name-lookup.cc                  | 14 ++++++++++----
>   gcc/testsuite/g++.dg/modules/using-9.C | 13 +++++++++++++
>   2 files changed, 23 insertions(+), 4 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/modules/using-9.C
> 
> diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
> index a8b9229b29e..512dc1be87f 100644
> --- a/gcc/cp/name-lookup.cc
> +++ b/gcc/cp/name-lookup.cc
> @@ -4846,12 +4846,18 @@ do_nonmember_using_decl (name_lookup &lookup, bool fn_scope_p,
>   	  bool exporting = revealing_p && module_exporting_p ();
>   	  if (exporting)
>   	    {
> +	      /* Module flags for templates are on the template_result.  */
> +	      tree decl = new_fn;
> +	      if (TREE_CODE (decl) == TEMPLATE_DECL)
> +		decl = DECL_TEMPLATE_RESULT (decl);
> +
>   	      /* If the using decl is exported, the things it refers
> -		 to must also be exported (or not habve module attachment).  */
> -	      if (!DECL_MODULE_EXPORT_P (new_fn)
> -		  && (DECL_LANG_SPECIFIC (new_fn)
> -		      && DECL_MODULE_ATTACH_P (new_fn)))
> +		 to must also be exported (or not have module attachment).  */
> +	      if (!DECL_MODULE_EXPORT_P (decl)
> +		  && (DECL_LANG_SPECIFIC (decl)
> +		      && DECL_MODULE_ATTACH_P (decl)))
>   		{
> +		  auto_diagnostic_group d;
>   		  error ("%q#D does not have external linkage", new_fn);
>   		  inform (DECL_SOURCE_LOCATION (new_fn),
>   			  "%q#D declared here", new_fn);
> diff --git a/gcc/testsuite/g++.dg/modules/using-9.C b/gcc/testsuite/g++.dg/modules/using-9.C
> new file mode 100644
> index 00000000000..4290280d897
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/using-9.C
> @@ -0,0 +1,13 @@
> +// PR c++/106849
> +// { dg-additional-options "-fmodules-ts" }
> +// { dg-module-cmi !lib }
> +
> +export module lib;
> +
> +namespace outer {
> +  template<typename T> void any_of(T) { }  // { dg-note "declared here" }
> +}
> +
> +export using outer::any_of;  // { dg-error "does not have external linkage" }
> +
> +// { dg-prune-output "not writing module" }

-- 
Nathan Sidwell


      reply	other threads:[~2023-11-09 22:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-09 21:06 Nathaniel Shead
2023-11-09 22:59 ` Nathan Sidwell [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9cef0501-26d3-4bc2-a895-d9ee32648ca8@acm.org \
    --to=nathan@acm.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=nathanieloshead@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).