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

[charconv.from.chars] Clarify the role of a 0x prefix in from_chars #6848

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Eisenwave
Copy link
Contributor

The current wording

... the prefix "0x" or "0X" is assumed.

... is ambiguous. It could either mean

  • the prefix is assumed to be at the start of the string (inclusive prefix), or
  • the prefix is assumed to precede the string (exclusive prefix).

In the English language, I don't believe that the inclusive/exclusive nature of prefixes is undisputed.

However, the following example with 0x123 disambiguates this, and this example has been present in P0067R5 (which was accepted).

Therefore, I believe intent is clear, and this issue is editorial. However, it would be better for the normative wording to be clear in itself instead of relying on a clarifying example.

@jwakely
Copy link
Member

jwakely commented Mar 3, 2024

I think it would be better to not use the word "assumed" at all. What does that assumption mean? Can the function subtract 2 from the pointer and assume that is a valid pointer and the characters "0x" will be present?

Can we phrase it in terms of the result being determined as if the prefix preceded the string, not assuming it actually does?

@Eisenwave Eisenwave force-pushed the charconv-clarify-hex-prefix branch from 2179c51 to b7a2300 Compare March 4, 2024 09:08
@Eisenwave
Copy link
Contributor Author

Can we phrase it in terms of the result being determined as if the prefix preceded the string, not assuming it actually does?

Well, it's a tough nut to crack. I've thought about it for quite a while and I've settled on "shall not appear", which is in line with the wording for the other bullets.

We don't assume anything anymore, we just say what shall and shall not be part of the subject sequence. I think that's an overall improvement and it's clear.

However, I feel like the wording for all three bullets is a bit messy; it feels clunky to use "shall" here instead of describing with "softer" wording what we consider to be part of the subject sequence.

What do you think?

@jwakely
Copy link
Member

jwakely commented Mar 4, 2024

Well, it's a tough nut to crack.

That's why I didn't suggest any specific wording ;-)

I don't think the new suggestion works at all. The current wording says the result is as though using strtod on a string that begins with "0x", so a hex float is parsed. If you remove that (and also say no 0x is allowed) then there's no way to parse a hex float. Nothing actually says that the hex format causes a hex float to be parsed. The assumed-to-be-present-but-not-actually-present 0x prefix causes that today.

@jwakely
Copy link
Member

jwakely commented Mar 4, 2024

We could describe it in terms of transforming the argument into a pattern in the form strtod expects, i.e. inserting the "0x" prefix and then parsing that. But then we'd need to be clear that the ptr member of the result gets to the original argument string not this imaginary one we talk about. I don't like this suggestion much.

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

Successfully merging this pull request may close these issues.

None yet

2 participants