alwaysAssert() [was: Against enforce()]

Jonathan M Davis jmdavisProg at gmx.com
Thu Mar 17 18:38:22 PDT 2011


On Thursday, March 17, 2011 18:23:51 Andrei Alexandrescu wrote:
> On 3/17/11 7:31 PM, Walter Bright wrote:
> > On 3/17/2011 5:02 PM, Andrei Alexandrescu wrote:
> >  > [...]
> > 
> > I don't disagree with anything you wrote. But I am suggesting that one
> > liners should have a high utility to be justifiably included in Phobos.
> > 
> > ---------------------------------
> > 
> > You mentioned wondering where we should draw the line in using asserts
> > to check function inputs as opposed to using enforce. I suggest that
> > line should be when a shared library/dll boundary is crossed. Statically
> > linked libs should use assert.
> > 
> > The reason is straightforward - a shared library/dll cannot know in
> > advance what will be connected to it, so it should treat data coming in
> > from an external source as untrusted input. A statically linked library,
> > on the other hand, is inextricably bound to a specific caller and is
> > debugged/tested as a whole.
> > 
> > This raises the spectre about what to do with Phobos if Phobos is built
> > as a dll.
> 
> These are all very good points and insights. We should keep them in mind.

It also brings us back to one of Bearophile's concerns. If you want assertions 
to be enabled in Phobos, you need a non-release build, and Phobos is distributed 
in non-release build. The only way to have a non-release build is to build it 
yourself and replace your libphobos.a (or phobos.lib) with the non-release 
version. Some folks want a way to make it so that there's a release and non-
release version of Phobos and dmd picks the release version when you compile 
with -release and picks the non-release version otherwise.

- Jonathan M Davis


More information about the Digitalmars-d mailing list