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

P0542R5 Support for contract based programming in C++ #2151

Merged
merged 17 commits into from Jun 19, 2018

Conversation

jensmaurer
Copy link
Member

Fixes #2126.

@jensmaurer jensmaurer added this to the post-2018-06 milestone Jun 10, 2018
source/basic.tex Outdated
@@ -550,6 +550,15 @@
requirement applies recursively)\footnote{\ref{dcl.fct.default}
describes how default argument names are looked up.}; and

\item if \tcode{D} is a function that
Copy link
Member

Choose a reason for hiding this comment

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

This "is a function" restriction is new, and appears to be incorrect for the "invokes a function with a precondition" part. Perhaps:

if D invokes a function with a precondition, or is a function that contains an assertion or has a postcondition, [...]

Copy link
Member Author

Choose a reason for hiding this comment

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

The "pure" model says preconditions are checked in the caller (so we need to account for that), but we have otherwise drafted wording that assumes (under as-if) that preconditions are actually evaluated in the callee. So, I think we should actually care for both places where precondition checking code could be emitted.

Copy link
Member

Choose a reason for hiding this comment

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

I agree. However, this appears to be a normative change relative to the wording we were given, so can you send an email to the core reflector to make sure this won't surprise anyone?

source/basic.tex Outdated
contains an assertion,
has a postcondition,
or invokes a function with a precondition,
the conditions under which each definition of \tcode{D}
Copy link
Member

Choose a reason for hiding this comment

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

This "the conditions under which" phrasing is awkward. Presumably the intent is that an implementation can say that some combinations are allowed and some are not, so we can't just say:

[...] it is implementation-defined whether all definitions of D shall be translated using the same build level and violation continuation mode.

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's my understanding that the implementation has to actually state the list of conditions, and the authors hope (in vain?) it's not "always", but something more modular and user-friendly.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've rephrased a bit more; it's now less awkward and still talks about "conditions".

@@ -4239,3 +4240,414 @@
could have the same address as \tcode{buckets}
if their respective types are all empty.
\end{example}

\rSec2[dcl.attr.contract]{Contract attributes}%
Copy link
Member

Choose a reason for hiding this comment

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

We keep the subclauses of [dcl.attr] in alphabetical order. (So far that's been by attribute name, but the contract attributes throw a spanner in the works here.)

I'm not sure what the best answer is here.

Copy link
Member Author

Choose a reason for hiding this comment

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

"We keep the subclauses of [dcl.attr] in alphabetical order."
Ah, that wasn't clear to me. But yes, the current list looks alphabetical.

Sort according to "contract" maybe? We already sort "likely" and "unlikely" under "likelihood".
@zygoloid, awaiting your answer before actually doing the move.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, let's sort by heading name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

\begin{bnf}
\nontermdef{contract-attribute-specifier}\br
\terminal{[} \terminal{[} \terminal{expects} \opt{contract-level} \terminal{:} conditional-expression \terminal{]} \terminal{]}\br
\terminal{[} \terminal{[} \terminal{ensures} \opt{contract-level} \terminal{:} \opt{identifier} \terminal{:} conditional-expression \terminal{]} \terminal{]}\br
Copy link
Member

Choose a reason for hiding this comment

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

There's a stray colon here before the identifier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Uh, right.
So, this is a "fixup" against the original paper transcription. I'd really like to move that commit as a "fixup" right after the original paper application, but how do I do that given that I'm not supposed to force-push?

Copy link
Member

Choose a reason for hiding this comment

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

What you did is fine, I'll figure out which commit it's a fixup for when I do the merging. Or if you're going to force push anyway to rebase and pick up the new header names table, you could merge it into the original paper commit yourself.

\end{note}

\pnum
The predicate of a contract is potentially evaluated\iref{basic.def.odr}.
Copy link
Member

Choose a reason for hiding this comment

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

Move this sentence to the end of paragraph 5. Also, we should convert it to a note, since this follows from the definition of "potentially evaluated".

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed; fixed.

setting or modifying the violation handler.
It is \impldef{argument for violation handler}
how the violation handler is established for a program and
how the \tcode{std::contract_violation} argument value is set.
Copy link
Member

Choose a reason for hiding this comment

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

I think we need an "except as specified below" here, since we're about to give some rules that dictate how parts of the contract_violation argument value are set.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed; also added a cross-reference to [support.contract.cviol].

}

struct C : A, B {
virtual void g(); // ill-formed, no diagnostic required
Copy link
Member

Choose a reason for hiding this comment

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

Wait, why is this "no diagnostic required"? The overrider doesn't satisfy the conditions of the ODR, and won't always produce the same value. This is just ill-formed, isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, fixed.

into the templated function, variable, or class
are two declarations of the same entity.
An \grammarterm{explicit-instantiation} of a function template
shall not specify a contract condition\iref{dcl.attr.contract}.
Copy link
Member

Choose a reason for hiding this comment

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

This is not an appropriate place for this rule (it's placed between a normative rule and its note and example). In fact, we often place such rules with the rules about the prohibited thing, not in the explicit instantiation rules. For example, [dcl.stc] disallows storage classes in explicit instantiations, and [except.spec] gives the rules for noexcept in explicit instantiations. But I would note that some other related rules are in [temp.explicit]p1: "An explicit instantiation of a function template, member function of a class template, or variable template shall not use the inline or constexpr specifiers." (And I'm not sure where we disallow an explicit instantiation from having default arguments...)

But this is also redundant. [dcl.attr.grammar]p5 says "No attribute-specifier-seq shall appertain to an explicit instantiation". So I think we should either drop this change or convert it to a note in p1.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed due to redundancy. I'm not adding a note; we should decide whether we want the "explicit instantiation" restriction in [temp.explicit] or where the other feature is defined, and consistently put notes in the "other" places. See #2188, for a later time.

@@ -1028,6 +1028,19 @@
\tcode{std::atexit} or \tcode{std::at_quick_exit}
exits via an exception\iref{support.start.term}, or

\item%
when evaluation of a predicate\iref{dcl.attr.contract}
Copy link
Member

Choose a reason for hiding this comment

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

"a predicate" -> "the predicate of a contract"

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@@ -1013,41 +1013,46 @@
{llll}
\topline
\tcode{<algorithm>} &
\tcode{<fstream>} &
Copy link
Member

Choose a reason for hiding this comment

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

This needs merging / rebasing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you want me to rebase (with force-push)? That is my preference; i have no idea what "merge" would do to me.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, pushing with --force-with-lease seems fine here. (I think that will probably do bad things to github's comment tracking, though I suppose there's only one way to find out.)

@jensmaurer jensmaurer added the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Jun 15, 2018
@zygoloid
Copy link
Member

All looks good so far. Thanks!

@jensmaurer jensmaurer removed the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Jun 17, 2018
@jensmaurer
Copy link
Member Author

Ok, pushed using --force-with-lease.

Also move rules on virtual functions to [class.virtual].
Rephase assertion checking along pre/postcondition checking.
as per the definition in [basic.def.odr], so turn the
redundant normative statement into a note.
given that [dcl.attr.grammar] already prohibits
attribute-specifier-seqs for an explicit instantiation.
@zygoloid zygoloid merged commit 8f613b7 into master Jun 19, 2018
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