public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-6526] c++: noexcept and copy elision [PR109030]
@ 2023-03-07 15:14 Marek Polacek
  0 siblings, 0 replies; only message in thread
From: Marek Polacek @ 2023-03-07 15:14 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:e4692319fd5fc7d740436e8bb338f44cb8df6c58

commit r13-6526-ge4692319fd5fc7d740436e8bb338f44cb8df6c58
Author: Marek Polacek <polacek@redhat.com>
Date:   Mon Mar 6 18:06:39 2023 -0500

    c++: noexcept and copy elision [PR109030]
    
    When processing a noexcept, constructors aren't elided: build_over_call
    has
             /* It's unsafe to elide the constructor when handling
                a noexcept-expression, it may evaluate to the wrong
                value (c++/53025).  */
             && (force_elide || cp_noexcept_operand == 0))
    so the assert I added recently needs to be relaxed a little bit.
    
            PR c++/109030
    
    gcc/cp/ChangeLog:
    
            * constexpr.cc (cxx_eval_call_expression): Relax assert.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/noexcept77.C: New test.

Diff:
---
 gcc/cp/constexpr.cc                     | 6 +++++-
 gcc/testsuite/g++.dg/cpp0x/noexcept77.C | 9 +++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 3079561f2e8..8683c00596a 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -2869,7 +2869,11 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
 
   /* We used to shortcut trivial constructor/op= here, but nowadays
      we can only get a trivial function here with -fno-elide-constructors.  */
-  gcc_checking_assert (!trivial_fn_p (fun) || !flag_elide_constructors);
+  gcc_checking_assert (!trivial_fn_p (fun)
+		       || !flag_elide_constructors
+		       /* We don't elide constructors when processing
+			  a noexcept-expression.  */
+		       || cp_noexcept_operand);
 
   bool non_constant_args = false;
   new_call.bindings
diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept77.C b/gcc/testsuite/g++.dg/cpp0x/noexcept77.C
new file mode 100644
index 00000000000..16db8eb79ee
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/noexcept77.C
@@ -0,0 +1,9 @@
+// PR c++/109030
+// { dg-do compile { target c++11 } }
+
+struct foo { };
+
+struct __as_receiver {
+  foo empty_env;
+};
+void sched(foo __fun) noexcept(noexcept(__as_receiver{__fun})) { }

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

only message in thread, other threads:[~2023-03-07 15:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-07 15:14 [gcc r13-6526] c++: noexcept and copy elision [PR109030] Marek Polacek

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