https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118661

            Bug ID: 118661
           Summary: Reading volatile qualified std::nullptr_t should be
                    valid in a constant expression
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: luigighiron at gmail dot com
  Target Milestone: ---

The following code is not accepted by GCC:

#include<cstddef>
constexpr volatile std::nullptr_t n{};
constexpr std::nullptr_t m=n;
int main(){}

Clang and MSVC accept this code. It should be valid since there is a specific
exemption for volatile std::nullptr_t in [expr.const], quoting section 7.7
paragraph 10 from N5001:
> An expression E is a core constant expression unless the evaluation of E,
> following the rules of the abstract machine (6.9.1), would evaluate one of the
> following:
> 
> ...
> 
> - an lvalue-to-rvalue conversion (7.3.2) unless it is applied to
>   - a glvalue of type cv std::nullptr_t,
>   - a non-volatile glvalue that refers to an object that is usable in constant
>     expressions, or
>   - a non-volatile glvalue of literal type that refers to a non-volatile
>     object whose lifetime began within the evaluation of E;

Reply via email to