public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/c++-modules] Instantiated noexcept specifications
@ 2020-03-17 20:22 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2020-03-17 20:22 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:736b82e061f5fb73f5f835253a0d74c2dceaafcb

commit 736b82e061f5fb73f5f835253a0d74c2dceaafcb
Author: Nathan Sidwell <nathan@acm.org>
Date:   Tue Mar 17 13:13:31 2020 -0700

    Instantiated noexcept specifications
    
            gcc/cp/
            * module.cc (trees_in::is_matching_decl): Propagate instantiated
            noexcept specifications.
            gcc/testsuite/
            * g++.dg/modules/except-3{,_[ab]}.[hHC]: New.

Diff:
---
 ChangeLog.modules                         |  6 ++++++
 gcc/cp/module.cc                          | 33 +++++++++++++++++++++++++++++++
 gcc/testsuite/g++.dg/modules/except-3.h   | 24 ++++++++++++++++++++++
 gcc/testsuite/g++.dg/modules/except-3_a.H |  6 ++++++
 gcc/testsuite/g++.dg/modules/except-3_b.C |  7 +++++++
 5 files changed, 76 insertions(+)

diff --git a/ChangeLog.modules b/ChangeLog.modules
index 65668f211be..fa4d5346de5 100644
--- a/ChangeLog.modules
+++ b/ChangeLog.modules
@@ -1,5 +1,11 @@
 2020-03-17  Nathan Sidwell  <nathan@acm.org>
 
+	gcc/cp/
+	* module.cc (trees_in::is_matching_decl): Propagate instantiated
+	noexcept specifications.
+	gcc/testsuite/
+	* g++.dg/modules/except-3{,_[ab]}.[hHC]: New.
+
 	gcc/cp/
 	* module.cc (lazy_snum, recursive_lazy): New.
 	(module_state::read_language): Set lazy_snum.
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index efab2cf88a0..60a7f2583fd 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -10430,6 +10430,39 @@ trees_in::is_matching_decl (tree existing, tree decl, tree inner)
       return false;
     }
 
+  if (TREE_CODE (decl) == FUNCTION_DECL)
+    {
+      /* If EXISTING has an undeduced or uninstantiated exception
+	 specification, but DECL does not, propagate the exception
+	 specification.  */
+      // FIXME: I don't think this can happen for a template
+      tree e_type = TREE_TYPE (existing);
+      tree e_spec = TYPE_RAISES_EXCEPTIONS (e_type);
+      if (DEFERRED_NOEXCEPT_SPEC_P (e_spec))
+	{
+	  tree d_type = TREE_TYPE (decl);
+	  tree d_spec = TYPE_RAISES_EXCEPTIONS (d_type);
+	  if (!DEFERRED_NOEXCEPT_SPEC_P (d_spec)
+	      || (UNEVALUATED_NOEXCEPT_SPEC_P (e_spec)
+		  && !UNEVALUATED_NOEXCEPT_SPEC_P (d_spec)))
+	    {
+	      dump (dumper::MERGE)
+		&& dump ("Propagating instantiated noexcept to %N", existing);
+	      TREE_TYPE (existing) = d_type;
+	      /* Propagate to existing clones.  */
+	      tree clone;
+	      FOR_EACH_CLONE (clone, existing)
+		{
+		  if (TREE_TYPE (clone) == e_type)
+		    TREE_TYPE (clone) = d_type;
+		  else
+		    TREE_TYPE (clone)
+		      = build_exception_variant (TREE_TYPE (clone), d_spec);
+		}
+	    }
+	}
+    }
+
   if (DECL_IS_BUILTIN (existing) && DECL_ANTICIPATED (existing))
     {
       // FIXME: Take the type from decl, see duplicate decls.  FIXME: Our
diff --git a/gcc/testsuite/g++.dg/modules/except-3.h b/gcc/testsuite/g++.dg/modules/except-3.h
new file mode 100644
index 00000000000..8bf0f84d590
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/except-3.h
@@ -0,0 +1,24 @@
+
+template<typename _Tp>
+struct is_nothrow_move_constructible
+{
+  static constexpr bool value = false;
+};
+
+template<typename _Head>
+struct _Tuple_impl
+{
+  _Tuple_impl () noexcept(is_nothrow_move_constructible<_Head>::value)
+ { }
+};
+
+template<typename T>
+void TPL (_Tuple_impl<T> &) noexcept
+{
+  _Tuple_impl<T> m;
+}
+
+inline void foo (_Tuple_impl<int> &p)
+{
+  TPL<int> (p);
+}
diff --git a/gcc/testsuite/g++.dg/modules/except-3_a.H b/gcc/testsuite/g++.dg/modules/except-3_a.H
new file mode 100644
index 00000000000..2f9f00e6222
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/except-3_a.H
@@ -0,0 +1,6 @@
+// { dg-additional-options -fmodule-header }
+// { dg-module-cmi {} }
+// We end up with instantiated noexcept specs in the CMI data matching
+// textually loaded fns with uninstantiated ones.  Have to propagate,
+// not reinstantiate.
+#include "except-3.h"
diff --git a/gcc/testsuite/g++.dg/modules/except-3_b.C b/gcc/testsuite/g++.dg/modules/except-3_b.C
new file mode 100644
index 00000000000..0cb84725b5a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/except-3_b.C
@@ -0,0 +1,7 @@
+// { dg-additional-options "-fmodules-ts -fno-module-lazy -fdump-lang-module-alias" }
+
+#include "except-3.h"
+import "except-3_a.H";
+
+// { dg-final { scan-lang-dump-times {merge key \(new\) function_decl:'::_Tuple_impl<int>::__[cd]t '} 3 module } }
+// { dg-final { scan-lang-dump-times {Propagating instantiated noexcept to '::_Tuple_impl<int>::__ct <int>'} 1 module } }


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

only message in thread, other threads:[~2020-03-17 20:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-17 20:22 [gcc/devel/c++-modules] Instantiated noexcept specifications 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).