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

Incorrect types for application of "temporary materialization conversion" in [conv.array] #5981

Open
hawkinsw opened this issue Nov 17, 2022 · 4 comments

Comments

@hawkinsw
Copy link
Contributor

I am sure that I am reading this incorrectly, but I believe that there is a slight wording mistake with respect to the reference to "temporary materialization conversion" in [conv.array].

In [conv.array], the text says:

An lvalue or rvalue of type “array of N T” or “array of unknown bound of T” can be converted to a prvalue of
type “pointer to T”. The temporary materialization conversion (7.3.5) is applied. The result is a pointer to
the first element of the array.

I see three different types here:

  1. The "source" types:
  • "array of N T" (call that S)
  • "array of unknown bound of T" (call that SS)
  1. The "destination" type: "pointer to T" (call that D)

However, the text of "temporary materialization conversion", seems to imply that the "source" and the "destination" types are the same (some T):

A prvalue of type T can be converted to an xvalue of type T.

The array-to-pointer decay seems to go from either

  1. S to D
  2. SS to D

Again, I am sure that I am missing something but I thought I would mention it regardless. I am sure that an editorial change could resolve the issue.

@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Nov 17, 2022

Temporary materialization conversion is not array-to-pointer decay, but the former can be a part of the latter. I'm not sure if anything needs clarification.

In the following example,

using A = int[1];
+A{0};
  1. the prvalue of type int[1] (A{0}) is converted to xvalue (a temporary object is created);
  2. a prvalue of type int* is produced, which points to the first element of the temporary array object.

IIUC, temporary materialization conversion only consists of 1, while array-to-pointer decay consists of 1 and 2.

@tkoeppe
Copy link
Contributor

tkoeppe commented Nov 17, 2022

The temporary materialization conversion (7.3.5) is applied.

All this is saying is that if you have an array prvalue, then it is materialized, i.e. you have a glvalue to whose first element you can then point. I'm not sure if any of this needs clarification?

@hawkinsw
Copy link
Contributor Author

Temporary materialization conversion is not array-to-pointer decay, but the former can be a part of the latter. I'm not sure if anything needs clarification.

Thank you for the response! Yes, I completely agree that they are separate and that one (array-to-pointer decay) uses the other (temporary materialization conversion) in certain cases.

In the following example,

using A = int[1];
+A{0};
1. the prvalue of type `int[1]` (`A{0}`) is converted to xvalue (a temporary object is created);

It is my understanding that it would be here that temporary materialization would take place. That seems to correspond to your understanding as well ... whew! :-)

I think in this example there are more than one temporary conversions happening and only one of them comes from the array-to-pointer decay. I think that (1) is a temporary materialization that is unrelated to the one defined in [conv.array].

2. a prvalue of type `int*` is produced, which points to the first element of the temporary array object.

I think that it would be here that the [conv.array] language comes in to play. Because we are doing + that means that we need the operand to be something +able and so the xvalue from (1) (of type int[1]) will "decay to pointer". As I continue to read the second [conv.array], we have here " “array of N T”... [that should be] converted to a prvalue of
type “pointer to T” ". Again, in my feeble attempt at understanding, I read [conv.array] to say that process occurs through temporary materialization conversion.

And this is where I get confused.

If my reading is correct, then, what goes in to temporary materialization conversion (a prvalue of type T) is akin what comes out (an xvalue of type T). But, in the situation we have here, what goes in is a prvalue of array of N T (where N is 1 and T is int) and what comes out is not an xvalue of array of N T (it is supposed to have the type of "pointer to the first element of the array").

Again, I am sure that I am misunderstanding something, but that is how I am reading it.

Thank you and @tkoeppe for the discussion! I hope that this discussion is helpful!

Will

IIUC, temporary materialization conversion only consists of 1, while array-to-pointer decay consists of 1 and 2.

@languagelawyer
Copy link
Contributor

In the following example,

using A = int[1];
+A{0};
1. the prvalue of type `int[1]` (`A{0}`) is converted to xvalue

This is just ill-formed. Or, you can say, this is CWG2548, which, in turn, should be closed as NAD confirming that ill-formedness is intended.

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

4 participants