Discussion:
What does "interpreted" mean in [expr.cast]?
(too old to reply)
Nicolas Lesser
2018-09-29 20:13:58 UTC
Permalink
The conversions performed by
- a const_­cast,
- a static_­cast,
- a static_­cast followed by a const_­cast,
- a reinterpret_­cast, or
- a reinterpret_­cast followed by a const_­cast,
can be performed using the cast notation of explicit type conversion.
[...] If a conversion can be interpreted in more than one of the ways
listed above, the interpretation that appears first in the list is used,
even if a cast resulting from that interpretation is ill-formed.

What does interpreted mean in the last sentence above? It seems
contradictory. So:

"If a conversion can be interpreted in more than one of the ways listed
above" => I understand this as saying that if a conversion is valid for
more than one of the cast combinations listed above, then:

"the interpretation that appears first in the list is used" => ok, that
makes sense. The first cast that is valid is used if there are more than
one possible choices.

"even if a cast resulting from that interpretation is ill-formed." what?!?
Now I'm confused. This does seem to imply that C style casts that do
anything else than acting as const_cast are ill-formed. After all, I can
interpret the explicit cast as const_cast, and then per the bit mentioned
here, it's ill-formed and thus we stop.

How can I choose an interpretation that is valid if that choice entails
invalid choices?

Am I missing/misunderstanding something? Thanks! :)
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Jens Maurer
2018-09-30 07:02:23 UTC
Permalink
The conversions performed by
- a const_­cast,
- a static_­cast,
- a static_­cast followed by a const_­cast,
- a reinterpret_­cast, or
- a reinterpret_­cast followed by a const_­cast,
can be performed using the cast notation of explicit type conversion. [...] If a conversion can be interpreted in more than one of the ways listed above, the interpretation that appears first in the list is used, even if a cast resulting from that interpretation is ill-formed.
"the interpretation that appears first in the list is used" => ok, that makes sense. The first cast that is valid is used if there are more than one possible choices.
"even if a cast resulting from that interpretation is ill-formed." what?!? Now I'm confused. This does seem to imply that C style casts that do anything else than acting as const_cast are ill-formed. After all, I can interpret the explicit cast as const_cast, and then per the bit mentioned here, it's ill-formed and thus we stop.
How can I choose an interpretation that is valid if that choice entails invalid choices?
Take [expr.static.cast]. There is a lot of phrasing there talking about
"x can be cast to y".

If one of these conditions is satisfied, you "lock on" to that interpretation
of the C-style cast. If, further down, you encounter "ill-formed" (e.g. due
to an ambiguous conversion), that makes your program ill-formed, it doesn't
cause that the next option in in the list above is tried.

No, it's not great wording.

Jens
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Continue reading on narkive:
Loading...