Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xmh0511 opened this issue Jun 8, 2021 · 6 comments
Open

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

xmh0511 opened this issue Jun 8, 2021 · 6 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Jun 8, 2021

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?

@xmh0511 xmh0511 changed the title Is a null pointer value of a type be called a pointer? Is a null pointer value of a pointer type be called a pointer? Jun 8, 2021
@jwakely
Copy link
Member

jwakely commented Jun 8, 2021

[expr.eq] p2 says "The converted operands shall have arithmetic, enumeration, pointer, or pointer-to-member type" so it seems obvious to me that when p3 says an operand "is a pointer" it means it has pointer type.

The obvious answer to your question is yes, everything that has pointer type is a pointer. I think you are reading too much into the list in [basic.align]. I read it as "a pointer to something, or a pointer past the end of something, or ..." not as a definition of what is and isn't "a pointer".

@xmh0511
Copy link
Contributor Author

xmh0511 commented Jun 8, 2021

[expr.eq] p2 says "The converted operands shall have arithmetic, enumeration, pointer, or pointer-to-member type" so it seems obvious to me that when p3 says an operand "is a pointer" it means it has pointer type.

Yes, you clearly explain the meaning of what is a pointer but it's not clear by the normative rule.

The obvious answer to your question is yes, everything that has pointer type is a pointer. I think you are reading too much into the list in [basic.align]. I read it as "a pointer to something, or a pointer past the end of something, or ..." not as a definition of what is and isn't "a pointer".

Could we highlight the concept by using the normative rule? The meaning(everything that has pointer type is a pointer) seems not clear in the standard. After all, all concepts about pointer are introduced by [basic.compound]. In order to make the meaning more readable, I think [basic.compound#3] might be changed to

Every value of pointer type is one of the following pointers:

  • [...]

That could indicate what you say "everything that has pointer type is a pointer.", and they can be subsumed to four kinds of pointers listed in the rule.

@jensmaurer
Copy link
Member

No.

We need to clearly differentiate between "pointer type" and "a value of pointer type". The list in [basic.compound] p3 addresses the latter question (and uses proper terminology to do that).

Instead, the ancient text in [expr.eq] should be changed to talk about "operands of pointer type" and then say "Comparing values of pointer type is defined as follows". The term "pointer" should not be used in the (core) portion of the standard.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Jun 8, 2021

No.

We need to clearly differentiate between "pointer type" and "a value of pointer type". The list in [basic.compound] p3 addresses the latter question (and uses proper terminology to do that).

Instead, the ancient text in [expr.eq] should be changed to talk about "operands of pointer type" and then say "Comparing values of pointer type is defined as follows". The term "pointer" should not be used in the (core) portion of the standard.

That's totally what I originally thought before issuing this question. But I also think we should clarify what can be called pointer by using a normative rule, after all, the wording "pointer" is referred to in many sections in the standard.

@jensmaurer
Copy link
Member

"But I also think we should clarify what can be called pointer by using a normative rule"

No, we need to inspect the instances of "pointer" use one-by-one and fix them one way or the other. For example, the section you quoted in [expr.eq] uses "pointer" for both "pointer type" and "value of pointer type". Not good, and not fixable by defining "pointer".

@xmh0511
Copy link
Contributor Author

xmh0511 commented Jun 8, 2021

"But I also think we should clarify what can be called pointer by using a normative rule"

No, we need to inspect the instances of "pointer" use one-by-one and fix them one way or the other. For example, the section you quoted in [expr.eq] uses "pointer" for both "pointer type" and "value of pointer type". Not good, and not fixable by defining "pointer".

Oh, I see it. You mean we should eliminate the wording " pointer" appeared in the normative rule in some sections, and replace it with its concrete meaning defined in [ basic. compound] according to the context. It sounds greate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants