public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] c++: fix constexpr noreturn diagnostic
@ 2023-12-04 23:41 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2023-12-04 23:41 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jonathan Wakely

Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

Mentioning a noreturn function does not involve an lvalue-rvalue
conversion.

gcc/cp/ChangeLog:

	* constexpr.cc (potential_constant_expression_1): Fix
	check for loading volatile lvalue.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/constexpr-noreturn1.C: New test.
---
 gcc/cp/constexpr.cc                              |  3 ++-
 gcc/testsuite/g++.dg/cpp0x/constexpr-noreturn1.C | 12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-noreturn1.C

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index b17e176aded..96c61666470 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -9387,7 +9387,8 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
        available, so we don't bother with switch tracking.  */
     return true;
 
-  if (TREE_THIS_VOLATILE (t) && want_rval)
+  if (TREE_THIS_VOLATILE (t) && want_rval
+      && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (t)))
     {
       if (flags & tf_error)
 	constexpr_error (loc, fundef_p, "lvalue-to-rvalue conversion of "
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-noreturn1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-noreturn1.C
new file mode 100644
index 00000000000..08c10e8dccb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-noreturn1.C
@@ -0,0 +1,12 @@
+// { dg-do compile { target c++11 } }
+// { dg-additional-options -Winvalid-constexpr }
+
+// We were giving a wrong error about loading a volatile value instead of the
+// proper error about calling a non-constexpr function.
+
+[[noreturn]] void f();
+
+constexpr int g()
+{
+  return f(), 42;	   // { dg-message "call to non-'constexpr' function" }
+}

base-commit: b6abc5dbfa5342347828b9feb4d9060071ff819c
-- 
2.39.3


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

only message in thread, other threads:[~2023-12-04 23:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-04 23:41 [pushed] c++: fix constexpr noreturn diagnostic Jason Merrill

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