]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: fix constexpr noreturn diagnostic
authorJason Merrill <jason@redhat.com>
Mon, 4 Dec 2023 22:42:13 +0000 (17:42 -0500)
committerJason Merrill <jason@redhat.com>
Mon, 4 Dec 2023 23:42:04 +0000 (18:42 -0500)
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
gcc/testsuite/g++.dg/cpp0x/constexpr-noreturn1.C [new file with mode: 0644]

index b17e176adedc1330d1a1eac65e858de489deaa49..96c6166647058ea1a1bf864a56f29682667da5a2 100644 (file)
@@ -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 (file)
index 0000000..08c10e8
--- /dev/null
@@ -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" }
+}