https://gcc.gnu.org/g:58b8c87b7fb281e35a6817cc91a292096fdc02dc

commit r15-892-g58b8c87b7fb281e35a6817cc91a292096fdc02dc
Author: Patrick Palka <ppa...@redhat.com>
Date:   Wed May 29 04:49:37 2024 -0400

    c++: canonicity of fn types w/ instantiated eh specs [PR115223]
    
    When propagating structural equality in build_cp_fntype_variant, we
    should consider structural equality of the exception-less variant, not
    of the given type which might use structural equality only because it
    has a (complex) noexcept-spec that we're intending to replace, as in
    maybe_instantiate_noexcept which calls build_exception_variant using
    the deferred-noexcept function type.  Otherwise we might pessimistically
    use structural equality for a function type with a simple instantiated
    noexcept-spec, leading to a LTO-triggered type verification failure if we
    later use that (structural-equality) type as the canonical version of
    some other variant.
    
            PR c++/115223
    
    gcc/cp/ChangeLog:
    
            * tree.cc (build_cp_fntype_variant): Propagate structural
            equality of the exception-less variant.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/noexcept87.C: New test.
    
    Reviewed-by: Jason Merrill <ja...@redhat.com>

Diff:
---
 gcc/cp/tree.cc                          |  4 ++++
 gcc/testsuite/g++.dg/cpp0x/noexcept87.C | 11 +++++++++++
 2 files changed, 15 insertions(+)

diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index fe3f034d000..72dd46e1bd1 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -2796,6 +2796,10 @@ build_cp_fntype_variant (tree type, cp_ref_qualifier 
rqual,
   bool complex_eh_spec_p = (cr && cr != noexcept_true_spec
                            && !UNPARSED_NOEXCEPT_SPEC_P (cr));
 
+  if (!complex_eh_spec_p && TYPE_RAISES_EXCEPTIONS (type))
+    /* We want to consider structural equality of the exception-less
+       variant since we'll be replacing the exception specification.  */
+    type = build_cp_fntype_variant (type, rqual, /*raises=*/NULL_TREE, late);
   if (TYPE_STRUCTURAL_EQUALITY_P (type) || complex_eh_spec_p)
     /* Propagate structural equality.  And always use structural equality
        for function types with a complex noexcept-spec since their identity
diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept87.C 
b/gcc/testsuite/g++.dg/cpp0x/noexcept87.C
new file mode 100644
index 00000000000..339569d15ae
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/noexcept87.C
@@ -0,0 +1,11 @@
+// PR c++/115223
+// { dg-do compile { target c++11 } }
+// { dg-additional-options -flto }
+
+template<class T>
+void f() noexcept(bool(T() || true));
+
+void g() { f<int>(); }
+
+using type = void;
+type callDestructorIfNecessary() noexcept {}

Reply via email to