Alberto Barbati
2018-11-16 09:34:28 UTC
Hi,
what is the effect of a contract violation during constant expression
evaluation? The only relevant part I found in N4778 is in
[dcl.attr.contract.check]/4
<http://eel.is/c++draft/dcl.attr.contract.check#4>:
During constant expression evaluation (7.7), only predicates of checked
mention the effects of a violation *during constant evaluation*. Therefore
I have to assume that a violation handler of some kind has to be called, as
described in the subsequent paragraph. However, the handler described there
is not a constexpr function, so it cannot be called during constant
evaluation! Mind that std::contract_violation is not a literal type and
doesn't have constexpr members, so it is not possible nor meaningful to
have a constexpr handler. I believe the intent here is to just make the
program ill-formed whenever a contract is violated during constant
evaluation, but if that's true, I think we should say that explicitly. If
that's not the intent, we might want to clarify what the intent is.
On a side note, at the present moment the only way for a user-provided
constexpr function to produce some kind of diagnostic is through a
static_assert declaration, which only accepts a string literal and issues a
diagnostic while also making the program ill-formed. Would it be
feasible/desirable to have a magic library function, specifically designed
to be used in constexpr functions and able to issue a compile-time
diagnostic from a compile-time constructed string and without making the
program ill-formed? I believe that it would greatly help debugging
constexpr functions.
My two eurocent,
Alberto
what is the effect of a contract violation during constant expression
evaluation? The only relevant part I found in N4778 is in
[dcl.attr.contract.check]/4
<http://eel.is/c++draft/dcl.attr.contract.check#4>:
During constant expression evaluation (7.7), only predicates of checked
contracts are evaluated. In other contexts, it is unspecified whether the
predicate for a contract that is not checked under the current build level
is evaluated; if the predicate of such a contract would evaluate to false,
the behavior is undefined.
However, this paragraph only says which contracts are checked, but does notpredicate for a contract that is not checked under the current build level
is evaluated; if the predicate of such a contract would evaluate to false,
the behavior is undefined.
mention the effects of a violation *during constant evaluation*. Therefore
I have to assume that a violation handler of some kind has to be called, as
described in the subsequent paragraph. However, the handler described there
is not a constexpr function, so it cannot be called during constant
evaluation! Mind that std::contract_violation is not a literal type and
doesn't have constexpr members, so it is not possible nor meaningful to
have a constexpr handler. I believe the intent here is to just make the
program ill-formed whenever a contract is violated during constant
evaluation, but if that's true, I think we should say that explicitly. If
that's not the intent, we might want to clarify what the intent is.
On a side note, at the present moment the only way for a user-provided
constexpr function to produce some kind of diagnostic is through a
static_assert declaration, which only accepts a string literal and issues a
diagnostic while also making the program ill-formed. Would it be
feasible/desirable to have a magic library function, specifically designed
to be used in constexpr functions and able to issue a compile-time
diagnostic from a compile-time constructed string and without making the
program ill-formed? I believe that it would greatly help debugging
constexpr functions.
My two eurocent,
Alberto
--
---
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/.
---
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/.