Discussion:
What is a semantic rule?
(too old to reply)
Language Lawyer
2018-08-29 01:21:05 UTC
Permalink
Is it any rule speaking about values of objects and relations between them?

For example, let's take a look at [expr.add]/4:
When an expression that has integral type is added to or subtracted from a pointer, the result has the type of the pointer operand.
If the expression P points to element x[i] of an array object x with n elements, the expressions P + J and J + P (where J has the value j) point to the (possibly-hypothetical) element x[i+j] if 0≤i+j≤n; otherwise, the behavior is undefined.

Is this requirement on the value of a pointer and the value of an integer expression a semantic rule?
--
---
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/.
h***@gmail.com
2018-08-29 14:34:39 UTC
Permalink
Post by Language Lawyer
Is it any rule speaking about values of objects and relations between them?
When an expression that has integral type is added to or subtracted from a
pointer, the result has the type of the pointer operand.
If the expression P points to element x[i] of an array object x with n
elements, the expressions P + J and J + P (where J has the value j) point
to the (possibly-hypothetical) element x[i+j] if 0≀i+j≀n; otherwise, the
behavior is undefined.
Is this requirement on the value of a pointer and the value of an integer
expression a semantic rule?
It would help to understand the context of where this question is coming
from, because the answer to the question may be designed to be irrelevant
through reaching the same outcome regardless of the answer. It is clear
here that there is no diagnosable rule involved. It is also clear that
undefined behaviour is in play.
--
---
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/.
Language Lawyer
2018-08-29 15:02:36 UTC
Permalink
Post by h***@gmail.com
Post by Language Lawyer
Is it any rule speaking about values of objects and relations between them?
When an expression that has integral type is added to or subtracted from a
pointer, the result has the type of the pointer operand.
If the expression P points to element x[i] of an array object x with n
elements, the expressions P + J and J + P (where J has the value j) point
to the (possibly-hypothetical) element x[i+j] if 0≤i+j≤n; otherwise, the
behavior is undefined.
Is this requirement on the value of a pointer and the value of an integer
expression a semantic rule?
It would help to understand the context of where this question is coming
from, because the answer to the question may be designed to be irrelevant
through reaching the same outcome regardless of the answer. It is clear
here that there is no diagnosable rule involved. It is also clear that
undefined behaviour is in play.
Thank you for the request to provide the context.
I reread the sentence and realized that I had overlooked something.
Namely, the Note to the definition of undefined behavior says:
"Undefined behavior may be expected when this document omits any explicit
definition of behavior or when a program uses an erroneous construct or
erroneous data."

I had overlooked the second part and was surprised that every violation
of a semantic rule not explicitly marked as UB (or for which no diagnostics
is required) has to be diagnosed.
Now I see that this is not the case.


Anyway, it would be great to have an explanation what semantic rules are, generally.
--
---
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/.
h***@gmail.com
2018-08-29 15:36:54 UTC
Permalink
Post by Language Lawyer
Thank you for the request to provide the context.
I reread the sentence and realized that I had overlooked something.
"Undefined behavior may be expected when this document omits any explicit
definition of behavior or when a program uses an erroneous construct or
erroneous data."
The sentence verges upon being meaningless. Some entity (in the general
sense) is permitted to expect undefined behaviour; however, such
expectations are not required to be fulfilled.
Post by Language Lawyer
I had overlooked the second part and was surprised that every violation
of a semantic rule not explicitly marked as UB (or for which no diagnostics
is required) has to be diagnosed.
Now I see that this is not the case.
The key question is indeed whether a diagnostic is required. The convention
used in the Standard is to use "shall" in order to form a requirement that
affects the well-formedness of a program.
Post by Language Lawyer
Anyway, it would be great to have an explanation what semantic rules are, generally.
I think that the wording is a bit lax here and that there could be a
distinction made between semantic rules and semantic requirements as terms
of art. Semantic requirements affect the well-formedness of a program. A
program may be well-formed with undefined behaviour (and the definition of
well-formed program also admits programs that are ill-formed...). Semantic
rules may be read as anywhere in the spectrum from "semantic requirements"
to "all of the statements made with regards to semantics, including those
written as statements of fact regarding C++". The latter interpretation
seems to see some usage with regards to C in the C Standard.
--
---
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/.
Language Lawyer
2018-08-29 16:31:43 UTC
Permalink
Post by h***@gmail.com
Post by Language Lawyer
Thank you for the request to provide the context.
I reread the sentence and realized that I had overlooked something.
"Undefined behavior may be expected when this document omits any explicit
definition of behavior or when a program uses an erroneous construct or
erroneous data."
The sentence verges upon being meaningless. Some entity (in the general
sense) is permitted to expect undefined behaviour; however, such
expectations are not required to be fulfilled.
Post by Language Lawyer
I had overlooked the second part and was surprised that every violation
of a semantic rule not explicitly marked as UB (or for which no diagnostics
is required) has to be diagnosed.
Now I see that this is not the case.
The key question is indeed whether a diagnostic is required. The convention
used in the Standard is to use "shall" in order to form a requirement that
affects the well-formedness of a program.
[dcl.ref]/5: A reference shall be initialized to refer to a valid object or function.

First of all, it is not 100% clear for me what "a valid object" is, so I've opened an editorial issue (maybe, it is well-known what does it mean, so I'll close it).
But the question is: is it a diagnosable semantic rule?

The Note following the sentence suggests that probably it is not:
[Note: In particular, a null reference cannot exist in a well-defined program, because the only way to create such a reference would be to bind it to the “object” obtained by indirection through a null pointer, which causes undefined behavior.
As described in [class.bit], a reference cannot be bound directly to a bit-field. — end note]

I suppose here "shall" is used to put a requirement on a well-defined, not a well-formed program.
--
---
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/.
h***@gmail.com
2018-08-29 20:32:49 UTC
Permalink
Post by Language Lawyer
On Wednesday, August 29, 2018 at 11:02:44 AM UTC-4, Language Lawyer
Post by Language Lawyer
Thank you for the request to provide the context.
I reread the sentence and realized that I had overlooked something.
"Undefined behavior may be expected when this document omits any
explicit
Post by Language Lawyer
definition of behavior or when a program uses an erroneous construct or
erroneous data."
The sentence verges upon being meaningless. Some entity (in the general
sense) is permitted to expect undefined behaviour; however, such
expectations are not required to be fulfilled.
Post by Language Lawyer
I had overlooked the second part and was surprised that every violation
of a semantic rule not explicitly marked as UB (or for which no diagnostics
is required) has to be diagnosed.
Now I see that this is not the case.
The key question is indeed whether a diagnostic is required. The
convention
used in the Standard is to use "shall" in order to form a requirement
that
affects the well-formedness of a program.
[dcl.ref]/5: A reference shall be initialized to refer to a valid object or function.
First of all, it is not 100% clear for me what "a valid object" is, so
I've opened an editorial issue (maybe, it is well-known what does it mean,
so I'll close it).
But the question is: is it a diagnosable semantic rule?
I think that the current wording conventions say "yes" and that they
consider this use of "shall" to be erroneous. Would you file an editorial
issue for this one?
Post by Language Lawyer
[Note: In particular, a null reference cannot exist in a well-defined
program, because the only way to create such a reference would be to bind
it to the “object” obtained by indirection through a null pointer, which
causes undefined behavior.
As described in [class.bit], a reference cannot be bound directly to a
bit-field. — end note]
I suppose here "shall" is used to put a requirement on a well-defined, not
a well-formed program.
--
---
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/.
Language Lawyer
2018-08-30 05:22:56 UTC
Permalink
Post by h***@gmail.com
Post by Language Lawyer
On Wednesday, August 29, 2018 at 11:02:44 AM UTC-4, Language Lawyer
Post by Language Lawyer
Thank you for the request to provide the context.
I reread the sentence and realized that I had overlooked something.
"Undefined behavior may be expected when this document omits any
explicit
Post by Language Lawyer
definition of behavior or when a program uses an erroneous construct or
erroneous data."
The sentence verges upon being meaningless. Some entity (in the general
sense) is permitted to expect undefined behaviour; however, such
expectations are not required to be fulfilled.
Post by Language Lawyer
I had overlooked the second part and was surprised that every violation
of a semantic rule not explicitly marked as UB (or for which no diagnostics
is required) has to be diagnosed.
Now I see that this is not the case.
The key question is indeed whether a diagnostic is required. The
convention
used in the Standard is to use "shall" in order to form a requirement
that
affects the well-formedness of a program.
[dcl.ref]/5: A reference shall be initialized to refer to a valid object or function.
First of all, it is not 100% clear for me what "a valid object" is, so
I've opened an editorial issue (maybe, it is well-known what does it mean,
so I'll close it).
But the question is: is it a diagnosable semantic rule?
I think that the current wording conventions say "yes" and that they
consider this use of "shall" to be erroneous. Would you file an editorial
issue for this one?
I've added it to the issue about what does "valid object" in this sentence means.
--
---
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/.
Johannes Sixt
2018-08-29 18:04:05 UTC
Permalink
Post by Language Lawyer
Anyway, it would be great to have an explanation what semantic rules are, generally.
In my book, everything that cannot be expressed in LR(0) or LALR(1) or
LL(1) syntax rules (pick your favorite, they are equivalent, AFAIR) is a
semantic rule. That is basically everything written in the Standard
except for the grammar productions.
--
---
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...