Open xmh0511 opened 1 year ago
I think we can just modify [expr.const] p5.9 as indicated:
- (5.9.2) ... ~;~ , or
- (5.9.3) a glvalue of type cv
std::nullptr_t
;
I believe that [conv.lval] p3 already implies that lvalue-to-rvalue conversion to a glvalue of type cv std::nullptr_t
never produces an indeterminate value, so [basic.indet] p2 seems unrelated to me.
I think we can just modify [expr.const] p5.9 as indicated:
- (5.9.2) ... ~;~ , or
- (5.9.3) a glvalue of type cv
std::nullptr_t
;I believe that [conv.lval] p3 already implies that lvalue-to-rvalue conversion to a glvalue of type cv
std::nullptr_t
never produces an indeterminate value, so [basic.indet] p2 seems unrelated to me.
Yes, that's the suggested resolution.
so [basic.indet] p2 seems unrelated to me.
No, [basic.indet] uniformly applies all objects with automatic or dynamic storage duration that has no initialization performed. a gvalue of std::nullptr_t
in this case does denote that object.
CWG2907
Since we never look at the value of a std::nullptr_t
object, it's irrelevant whether its value is indeterminate or erroneous.
Needs cv
Or maybe not quite. I don't know what we want to do about the volatile std::nullptr_t
case.
Added cv; [conv.lval] has it, too.
Full name of submitter (unless configured in github; will be published with the issue): Jim X
Consider this example
According to [dcl.init.general] p12
[basic.types.general] p9
Hence, [dcl.init.general] p7.3 applies here
So, the variable at
#1
has no initialization. Then, at#2
, the full-expression of the initialization comprises: lvalue-to-rvalue conversion tonp
([conv.lval]), and null pointer conversion([conv.ptr])[conv.lval] p3 says
The lvalue-to-rvalue conversion to a glvalue of type
cv std::nullptr_t
seems not to care whether the the glvalue is initialized. However, [basic.indet] saysMoreover,
np
is not usable in constant expressions according to [expr.const] p2, [expr.const] p3, and [expr.const] p4. So, the evaluation of the full-expression of the initialization at least violates [expr.const] p5However, GCC and Clang both accept this example, only msvc rejects it.
Suggested resolution
Anyway, [conv.lval] p3.1 implies that the result of lvalue-to-rvalue conversion to any glvlaue of type
std::nullptr_t
(regardless of whether it is initialized or uninitialized), the result is always a null pointer constant.[expr.const] p5.9 and [basic.indet] p2 should have the special specification for
std::nullptr_t
.