Discussion:
Are attributes allowed to change observable behaviour now?
(too old to reply)
Brian Bi
2018-11-12 19:19:21 UTC
Permalink
I saw that C++20 contracts are specified as attributes, and that a contract
violation results in a "violation handler" function being called. See
https://en.cppreference.com/w/cpp/language/attributes/contract

I was told at one point that the design philosophy of attributes was that
their presence or absence shouldn't change a program's observable
behaviour. It seems that contracts do not follow this rule, since the
contract attributes affect whether the violation handler is called, and the
handler may have observable side effects such as logging.

To avoid allowing attributes to be used "to create language dialects"
<http://www.stroustrup.com/C++11FAQ.html#attributes>, I'd guess the new
rule is that attributes *are* allowed to affect observable behaviour but
that there shall be no way for the program itself to determine the presence
or absence of an attribute, so that only the Standard may define the
meaning of an attribute. However, I saw that P1144R0 proposes a new
[[trivially_relocatable]] attribute whose presence could be detected with
the std::is_trivially_relocatable trait, so it appears that even this
restriction is no longer in place. Are attributes now the preferred
mechanism for adding new keywords to the language?

Thanks
--
*Brian Bi*
--
---
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/.
Nicolas Lesser
2018-11-12 19:28:33 UTC
Permalink
Contracts are not attributes though :)
Post by Brian Bi
I saw that C++20 contracts are specified as attributes, and that a
contract violation results in a "violation handler" function being called.
See https://en.cppreference.com/w/cpp/language/attributes/contract
I was told at one point that the design philosophy of attributes was that
their presence or absence shouldn't change a program's observable
behaviour. It seems that contracts do not follow this rule, since the
contract attributes affect whether the violation handler is called, and the
handler may have observable side effects such as logging.
To avoid allowing attributes to be used "to create language dialects"
<http://www.stroustrup.com/C++11FAQ.html#attributes>, I'd guess the new
rule is that attributes *are* allowed to affect observable behaviour but
that there shall be no way for the program itself to determine the presence
or absence of an attribute, so that only the Standard may define the
meaning of an attribute. However, I saw that P1144R0 proposes a new
[[trivially_relocatable]] attribute whose presence could be detected with
the std::is_trivially_relocatable trait, so it appears that even this
restriction is no longer in place. Are attributes now the preferred
mechanism for adding new keywords to the language?
Thanks
--
*Brian Bi*
--
---
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
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/.
Brian Bi
2018-11-12 19:30:11 UTC
Permalink
"Contract attributes are used to specify preconditions, postconditions, and
assertions for functions.
<http://eel.is/c++draft/dcl.attr.contract#syn-1.sentence-1> "

http://eel.is/c++draft/dcl.attr.contract#syn-1
Post by Nicolas Lesser
Contracts are not attributes though :)
Post by Brian Bi
I saw that C++20 contracts are specified as attributes, and that a
contract violation results in a "violation handler" function being called.
See https://en.cppreference.com/w/cpp/language/attributes/contract
I was told at one point that the design philosophy of attributes was that
their presence or absence shouldn't change a program's observable
behaviour. It seems that contracts do not follow this rule, since the
contract attributes affect whether the violation handler is called, and the
handler may have observable side effects such as logging.
To avoid allowing attributes to be used "to create language dialects"
<http://www.stroustrup.com/C++11FAQ.html#attributes>, I'd guess the new
rule is that attributes *are* allowed to affect observable behaviour but
that there shall be no way for the program itself to determine the presence
or absence of an attribute, so that only the Standard may define the
meaning of an attribute. However, I saw that P1144R0 proposes a new
[[trivially_relocatable]] attribute whose presence could be detected with
the std::is_trivially_relocatable trait, so it appears that even this
restriction is no longer in place. Are attributes now the preferred
mechanism for adding new keywords to the language?
Thanks
--
*Brian Bi*
--
---
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
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
Visit this group at
https://groups.google.com/a/isocpp.org/group/std-discussion/.
--
*Brian Bi*
--
---
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/.
Richard Smith
2018-11-12 19:36:56 UTC
Permalink
Post by Brian Bi
I saw that C++20 contracts are specified as attributes, and that a
contract violation results in a "violation handler" function being called.
See https://en.cppreference.com/w/cpp/language/attributes/contract
I was told at one point that the design philosophy of attributes was that
their presence or absence shouldn't change a program's observable behaviour.
You were misinformed. Rather, the rule is more that an implementation that
doesn't implement the attribute at all (and merely produces a diagnostic
and ignores the attribute) is a correct implementation. And that is true
for attributes; such an implementation would be a conforming implementation
with build level "off".
Post by Brian Bi
It seems that contracts do not follow this rule, since the contract
attributes affect whether the violation handler is called, and the handler
may have observable side effects such as logging.
To avoid allowing attributes to be used "to create language dialects"
<http://www.stroustrup.com/C++11FAQ.html#attributes>, I'd guess the new
rule is that attributes *are* allowed to affect observable behaviour but
that there shall be no way for the program itself to determine the presence
or absence of an attribute, so that only the Standard may define the
meaning of an attribute. However, I saw that P1144R0 proposes a new
[[trivially_relocatable]] attribute whose presence could be detected with
the std::is_trivially_relocatable trait, so it appears that even this
restriction is no longer in place. Are attributes now the preferred
mechanism for adding new keywords to the language?
Thanks
--
*Brian Bi*
--
---
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
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/.
Richard Smith
2018-11-12 19:37:25 UTC
Permalink
Post by Richard Smith
Post by Brian Bi
I saw that C++20 contracts are specified as attributes, and that a
contract violation results in a "violation handler" function being called.
See https://en.cppreference.com/w/cpp/language/attributes/contract
I was told at one point that the design philosophy of attributes was that
their presence or absence shouldn't change a program's observable behaviour.
You were misinformed. Rather, the rule is more that an implementation that
doesn't implement the attribute at all (and merely produces a diagnostic
and ignores the attribute) is a correct implementation. And that is true
for attributes;
Err, true for /contracts/.
Post by Richard Smith
such an implementation would be a conforming implementation with build
level "off".
Post by Brian Bi
It seems that contracts do not follow this rule, since the contract
attributes affect whether the violation handler is called, and the handler
may have observable side effects such as logging.
To avoid allowing attributes to be used "to create language dialects"
<http://www.stroustrup.com/C++11FAQ.html#attributes>, I'd guess the new
rule is that attributes *are* allowed to affect observable behaviour but
that there shall be no way for the program itself to determine the presence
or absence of an attribute, so that only the Standard may define the
meaning of an attribute. However, I saw that P1144R0 proposes a new
[[trivially_relocatable]] attribute whose presence could be detected with
the std::is_trivially_relocatable trait, so it appears that even this
restriction is no longer in place. Are attributes now the preferred
mechanism for adding new keywords to the language?
Thanks
--
*Brian Bi*
--
---
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
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/.
Continue reading on narkive:
Loading...