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

[dcl.attr.contract.cond] example fails to return #2668

Merged
merged 3 commits into from Mar 15, 2019

Conversation

jfbastien
Copy link
Contributor

The function in the example returns int but fails to actually return.

The function in the example returns int but fails to actually return.
@@ -8458,6 +8458,7 @@
[[ensures r: p != nullptr]]
{
*p = 42; // OK, \tcode{p} is not modified
return p;
Copy link
Member

Choose a reason for hiding this comment

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

p is not an int. Maybe change the return type to void and remove the r from the contract?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to *p.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is trying to show something about ensures with returns?

Copy link
Contributor

Choose a reason for hiding this comment

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

The paragraph to which this example is attached:

If a postcondition odr-uses a parameter in its predicate and the function body makes direct or indirect modifications of the value of that parameter, the behavior is undefined

suggests it's trying to show that it's ok to refer to a parameter in an ensures when the function body doesn't modify it. The r is extraneous here, as is the int return value.

(Mind you, I'm unsure how the example in [dcl.attr.contract.syn]/6:

void push(int x, queue & q)
  [[expects: !q.full()]]
  [[ensures: !q.empty()]]
{
  /* ... */
  [[assert: q.is_valid()]];
  /* ... */
}

is supposed to ensure !q.empty() without "directly or indirectly modifying the value" of q - but this particular example seems sensible.)

Copy link
Member

Choose a reason for hiding this comment

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

The intent here is that the "value of the parameter" for a reference parameter is just the lvalue to which the reference is bound (which obviously cannot change during the execution of the function). Put another way, evaluating the postcondition in the caller with the values that it passed in should do the same thing as evaluating it in the callee. Can you open a separate editorial issue for that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you open a separate editorial issue for that?

Filed as #2669.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated accordingly.

@zygoloid zygoloid merged commit c769f83 into cplusplus:master Mar 15, 2019
@jfbastien jfbastien deleted the patch-6 branch March 15, 2019 17:31
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