public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-5460] c++: Fix exported using decls of templates
@ 2023-11-14 19:43 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2023-11-14 19:43 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5b9ecce87e8f315e2681743d75401991cdfefa71

commit r14-5460-g5b9ecce87e8f315e2681743d75401991cdfefa71
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date:   Thu Nov 9 19:05:09 2023 -0500

    c++: Fix exported using decls of templates
    
    We need to look at DECL_TEMPLATE_RESULT to get the module attachment.
    
            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>
    Signed-off-by: Nathan Sidwell <nathan@acm.org>

Diff:
---
 gcc/cp/name-lookup.cc                  | 12 ++++++++----
 gcc/testsuite/g++.dg/modules/using-9.C | 13 +++++++++++++
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index a8b9229b29e..50aeb776ae2 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -4846,12 +4846,16 @@ 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 = STRIP_TEMPLATE (new_fn);
+
 	      /* 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" }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-14 19:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-14 19:43 [gcc r14-5460] c++: Fix exported using decls of templates Nathan Sidwell

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).