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

[string.view.ops] convert Effects to Returns paragraphs #6818

Closed

Conversation

Eisenwave
Copy link
Contributor

No description provided.

@@ -1189,7 +1189,7 @@

\pnum
\effects
Equivalent to \tcode{traits::copy(s, data() + pos, rlen)}.
Equivalent to: \tcode{traits::copy(s, data() + pos, rlen)}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\effects
Equivalent to: \tcode{return substr(pos1, n1).compare(str);}
\returns
\tcode{substr(pos1, n1).compare(str)}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has normative effect, because it no longer inherits the preconditions and other specification from substr.

e.g. what happens if pos1 is out of range? The current wording defines that, your change doesn't.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See [structure.specifications] p4.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See [structure.specifications] p4.

Hmm, I think you're right, but it still surprises me. Isn't there a substantial amount of \returns uses which are broken then?

For example [string.conversions] p7 simply defines Returns for std::to_string, but no Preconditions or Throws specification.

However, this ultimately forwards to vformat which does have Throws. Does this mean that std::to_string never throws, or does it mean that std::to_string inherits its Throws (although this isn't specified)?

I feel like there's a larger issue. I've always assumed that Returns does inherit Preconditions, Throws, etc.

Copy link
Member

@jwakely jwakely Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See [structure.specifications] p4.

Hmm, I think you're right, but it still surprises me. Isn't there a substantial amount of \returns uses which are broken then?

No.

For example [string.conversions] p7 simply defines Returns for std::to_string, but no Preconditions or Throws specification.

Those functions have no preconditions, so that's fine.
They are allowed to throw anything, which might be somewhat underspecified but isn't broken.

However, this ultimately forwards to vformat which does have Throws. Does this mean that std::to_string never throws,

No! It has to be noexcept or say "Throws: nothing" for that to be true. Those functions can throw anything.

or does it mean that std::to_string inherits its Throws (although this isn't specified)?

No. It will never throw a format_error for example, and it can only throw bad_alloc in practice. But since we don't say what it can throw, it's technically allowed to throw anything (modulo the global restriction that the library only throws things derived from exception).

I feel like there's a larger issue.

I don't think so. The vast majority of cases are written as intended, and correct as written. There might be exceptions of course.

If we want to restrict what they're allowed to throw we could add a Throws element.

I've always assumed that Returns does inherit Preconditions, Throws, etc.

Definitely not, it only tells you the value that is returned. It says nothing about how that's actually achieved.

@jensmaurer
Copy link
Member

Closing this as going in the wrong direction.

@jensmaurer jensmaurer closed this Feb 22, 2024
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

3 participants