diff options
author | Jason Merrill <jason@redhat.com> | 2023-12-04 17:42:13 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2023-12-04 18:42:04 -0500 |
commit | 4c7185512115b13ab62a95970d37c8fd05e62eed (patch) | |
tree | 3d310db0206ecd303694ef58ce2dbc345be31446 | |
parent | 886f256ce3be4aa85f30af88558f0dfcb8003300 (diff) | |
download | gcc-4c7185512115b13ab62a95970d37c8fd05e62eed.zip gcc-4c7185512115b13ab62a95970d37c8fd05e62eed.tar.gz gcc-4c7185512115b13ab62a95970d37c8fd05e62eed.tar.bz2 |
c++: fix constexpr noreturn diagnostic
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.
-rw-r--r-- | gcc/cp/constexpr.cc | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/constexpr-noreturn1.C | 12 |
2 files changed, 14 insertions, 1 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index b17e176..96c6166 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 0000000..08c10e8 --- /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" } +} |