assume, assert, enforce, @safe

Artur Skawina via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 31 20:32:26 PDT 2014


On 08/01/14 04:33, Daniel Murphy via Digitalmars-d wrote:
> "Artur Skawina via Digitalmars-d"  wrote in message news:mailman.324.1406835164.16021.digitalmars-d at puremagic.com...
> 
>> > The corner case is "assert(0)".  It means "if the program got to here, > the impossible
>> has happened."
>>
>> It's vaguely defined, overloaded, and not currently treated that way.
>> Arguably it could mean 'this path won't ever be reached, trust me', but
>> redefining it now is obviously not possible. (doing this would of course
>> make assert(0) extremely dangerous)
> 
> You should probably read the spec on assert.  The assert(0) case is already defined that way.

No, that definition is contradictory ("vaguely defined" was an euphemism).
Requiring either AssertError or halting execution precludes treating assert(0)
as "unreachable code". Removing that requirement would change the meaning of
every existing (reachable) assert(0); all of them would then trigger undefined
behavior...

artur


More information about the Digitalmars-d mailing list