On 29/08/18 20:36,
hubert.rein...@gmail.com wrote:
> On Wednesday, August 29, 2018 at 11:02:44 AM UTC-4, Language Lawyer wrote:
>>
>> 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."
>>
> 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.
>
>
>>
>> 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.