]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Allow constexpr reads from volatile std::nullptr_t objects [PR118661]
authorJakub Jelinek <jakub@redhat.com>
Fri, 7 Feb 2025 13:27:18 +0000 (14:27 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 13 Jun 2025 09:53:58 +0000 (11:53 +0200)
commitc95cd1c5effaec023360c902b38376dc461d41e4
treeebcd150fa5c5116a75457232bcff22f8a7a2c29a
parented3daf6801f4b562d6fd80f134a2c68398fe5c00
c++: Allow constexpr reads from volatile std::nullptr_t objects [PR118661]

As mentioned in the PR, https://eel.is/c++draft/conv.lval#note-1
says that even volatile reads from std::nullptr_t typed objects actually
don't read anything and https://eel.is/c++draft/expr.const#10.9
says that even those are ok in constant expressions.

So, the following patch adjusts the r9-4793 changes to have an exception
for NULLPTR_TYPE.
As [conv.lval]/3 also talks about accessing to inactive member, I've added
testcase to cover that as well.

2025-02-07  Jakub Jelinek  <jakub@redhat.com>

PR c++/118661
* constexpr.cc (potential_constant_expression_1): Don't diagnose
lvalue-to-rvalue conversion of volatile lvalue if it has NULLPTR_TYPE.
* decl2.cc (decl_maybe_constant_var_p): Return true for constexpr
decls with NULLPTR_TYPE even if they are volatile.

* g++.dg/cpp0x/constexpr-volatile4.C: New test.
* g++.dg/cpp0x/constexpr-union9.C: New test.

(cherry picked from commit 6c8e6d6febaed3c167ca9534935c2cb18045528e)
gcc/cp/constexpr.cc
gcc/cp/decl2.cc
gcc/testsuite/g++.dg/cpp0x/constexpr-union9.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/constexpr-volatile4.C [new file with mode: 0644]