[MLton-commit] r4542

Stephen Weeks MLton@mlton.org
Mon, 15 May 2006 18:29:32 -0700


Tweaked the assert macro to call a dummy "asok" function in the event
that the assertion is true.  This avoids spurious warnings like the
following:

  gc/mark-compact.c:18: warning: statement with no effect
  gc/mark-compact.c:30: warning: statement with no effect

These warnings come when compiling with -pedantic -Wall, and appear to
be due to gcc simplifying the assert test (p) in

  (p) ? (void)0 : asfail(__FILE__, __LINE__, #p)

to TRUE at compile time and replacing expression with (void)0.  Now,
why this should cause a warning is beyond me, since (void)0 by itself
as source code doesn't.

Anyways, introducing the call to "asok" instead of (void)0 suppresses
the warning.  And the performance shouldn't matter since this is an
assert and is only on when debugging.


----------------------------------------------------------------------

U   mlton/branches/on-20050822-x86_64-branch/runtime/util/assert.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/util/assert.h

----------------------------------------------------------------------

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/util/assert.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/util/assert.c	2006-05-16 00:49:09 UTC (rev 4541)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/util/assert.c	2006-05-16 01:29:31 UTC (rev 4542)
@@ -7,6 +7,9 @@
 
 #include "util.h"
 
+void asok (void) {
+}
+
 void asfail(const char *file, int line, const char *prop) {
   fflush(stdout);
   fprintf(stderr, "%s:%d: assert(%s) failed.\n", file, line, prop);

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/util/assert.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/util/assert.h	2006-05-16 00:49:09 UTC (rev 4541)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/util/assert.h	2006-05-16 01:29:31 UTC (rev 4542)
@@ -13,9 +13,11 @@
 extern void asfail (const char *file, int line, const char *prop)
                         __attribute__ ((noreturn));
 
+extern void asok (void);
+
 /* Assertion verifier */
 #if ASSERT
-#define assert(p) ((p) ? (void)0 : asfail(__FILE__, __LINE__, #p))
+#define assert(p) ((p) ? asok() : asfail(__FILE__, __LINE__, #p))
 #else
 #define assert(p) ((void)0)
 #endif