www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - assert(false) with -unittest

reply Jens Mueller <jens.k.mueller gmx.de> writes:
Hi,

assert(false) should generate the hlt instruction in release mode.
I.e.
assert.d:
void hlt() {
	assert(false);
}

$ dmd -release -c assert.d
$ obj2asm assert.o | grep -w hlt

works. But

$ dmd -unittest -release -c assert.d
$ obj2asm assert.o | grep -w hlt

fails.

Can't one have hlt together with unittest? Is it a bug in the compiler
or correct behavior?

Jens
Nov 16 2010
next sibling parent reply dsimcha <dsimcha yahoo.com> writes:
== Quote from Jens Mueller (jens.k.mueller gmx.de)'s article
 Hi,
 assert(false) should generate the hlt instruction in release mode.
 I.e.
 assert.d:
 void hlt() {
 	assert(false);
 }
 $ dmd -release -c assert.d
 $ obj2asm assert.o | grep -w hlt
 works. But
 $ dmd -unittest -release -c assert.d
 $ obj2asm assert.o | grep -w hlt
 fails.
 Can't one have hlt together with unittest? Is it a bug in the compiler
 or correct behavior?
 Jens
I think this is correct. The -unittest switch implicitly turns on asserts, and as far as I can tell makes the -release switch ignored. This means that assert(false) is no longer special and works just like a regular assert as per TDPL. Is this a problem in practice? If so, please explain.
Nov 16 2010
parent Jens Mueller <jens.k.mueller gmx.de> writes:
dsimcha wrote:
 == Quote from Jens Mueller (jens.k.mueller gmx.de)'s article
 Hi,
 assert(false) should generate the hlt instruction in release mode.
 I.e.
 assert.d:
 void hlt() {
 	assert(false);
 }
 $ dmd -release -c assert.d
 $ obj2asm assert.o | grep -w hlt
 works. But
 $ dmd -unittest -release -c assert.d
 $ obj2asm assert.o | grep -w hlt
 fails.
 Can't one have hlt together with unittest? Is it a bug in the compiler
 or correct behavior?
 Jens
I think this is correct. The -unittest switch implicitly turns on asserts, and as far as I can tell makes the -release switch ignored. This means that assert(false) is no longer special and works just like a regular assert as per TDPL.
I see.
 Is this a problem in practice?  If so, please explain.
Haven't thought about it. Found this by accident. Jens
Nov 16 2010
prev sibling parent bearophile <bearophileHUGS lycos.com> writes:
dsimcha:

 I think this is correct.  The -unittest switch implicitly turns on asserts,
and as
 far as I can tell makes the -release switch ignored.  This means that
 assert(false) is no longer special and works just like a regular assert as per
TDPL.
 
 Is this a problem in practice?  If so, please explain.
We have recently discussed a related topic. That works according to the specs. But mixing the halt with asserts is not tidy and it's not good. The conclusion was that the design is bad, but apparently it's not bad enough to justify a fix. Bye, bearophile
Nov 16 2010