assert semantic change proposal

David Bregman via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 5 15:09:29 PDT 2014


On Tuesday, 5 August 2014 at 20:50:06 UTC, Jeremy Powers via 
Digitalmars-d wrote:
>>
>>
>>> Well, yes: Undefined behaviour in the sense
>>>
>> "And there will be no injection of undefined behaviour
>>                                    ^~~~~~~~~~~~~~~~~~~
>>                                    conventional sense
>>
>>
>>  - the undefined behaviour is already there if the asserted 
>> constraints
>>        ^~~~~~~~~~~~~~~~~~~
>>        altered sense
>>
>> are not valid."
>>
>
>
> I still don't quite see your point.  Perhaps I should have 
> said:  In the
> case where an asserted constraint is not met, the program is 
> invalid.
>  Being invalid it has undefined behaviour if it continues.
>
>>From another:
>
>> There is a difference between invalid and undefined: A program 
>> is invalid
>> ("buggy"), if it doesn't do what it's programmer intended, 
>> while
>> "undefined" is a matter of the language specification. The 
>> (wrong)
>> behaviour of an invalid program need not be undefined, and 
>> often isn't in
>> practice.
>>
>
> I disagree with this characterization.  Something can be buggy, 
> not doing
> what the programmer intended, while also a perfectly valid 
> program.  You
> can make wrong logic that is valid/reasonable in the context of 
> the program.
>
> Invalid in this case means the programmer has explicitly stated 
> certain
> constraints must hold, and such constraints do not hold.  So if 
> you
> continue with the program in the face of invalid constraints, 
> you have no
> guarantee what will happen - this is what I mean by 'undefined'.

You're using a nonstandard definition of undefined behavior. 
Undefined behavior has a precise meaning, that's why Timon linked 
the wiki article for you.

The regular definition of assert does not involve any undefined 
behavior, only the newly proposed one.


More information about the Digitalmars-d mailing list