Skip to content

Is a null pointer value of a pointer type be called a pointer? #4662

Open
@xmh0511

Description

@xmh0511

Please see this example

 (void*)0 == (char*)0;

The operands of the equal operator are a null pointer value of type void* and a null pointer value of type char*, respectively as per:

A null pointer constant is an integer literal ([lex.icon]) with value zero or a prvalue of type std​::​nullptr_­t. A null pointer constant can be converted to a pointer type; the result is the null pointer value of that type ([basic.compound]) and is distinguishable from every other value of object pointer or function pointer type.

Meanwhile, [expr.eq#3] states that

If at least one of the operands is a pointer, pointer conversions, function pointer conversions, and qualification conversions are performed on both operands to bring them to their composite pointer type. Comparing pointers is defined as follows:

The two operands after conversion should both be pointers if one of them is original a pointer. However, according to the relevant rule in [basic.compound]#3

Except for pointers to static members, text referring to “pointers” does not apply to pointers to members. Pointers to incomplete types are allowed although there are restrictions on what can be done with them ([basic.align]). Every value of pointer type is one of the following:

  • a pointer to an object or function (the pointer is said to point to the object or function), or
  • a pointer past the end of an object ([expr.add]), or
  • the null pointer value for that type, or
  • an invalid pointer value.

Except for the first two bullets, they are explicitly called pointer; the remaining cases are not explicitly called pointer. In other words, Can a null pointer value or invalid pointer value be called a pointer? It seems that there is no rule elsewhere in the standard that states any value of pointer type is called a pointer. If it is say, the two operands of the equal operator should be invalid in this example.

Anyway, the issue here is that, Is an arbitrary value of pointer type called pointer?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions