changeset 33251:93b856b2d87e

don't allow error_if and error_unless macros to be defined to be empty * error.h (error_if, error_unless): Don't allow these macros to be defined away by compiling with NDEBUG defined. Update comments to discourage using error_if, error_impossible, and error_unless.
author John W. Eaton <jwe@octave.org>
date Mon, 25 Mar 2024 13:49:47 -0400
parents 40fde86be9b0
children 737ab816cb7b a42aa7e5dd29
files libinterp/corefcn/error.h
diffstat 1 files changed, 13 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/error.h	Mon Mar 25 00:42:04 2024 -0400
+++ b/libinterp/corefcn/error.h	Mon Mar 25 13:49:47 2024 -0400
@@ -493,20 +493,23 @@
 extern OCTINTERP_API void
 parse_error_with_id (const char *id, const char *fmt, ...);
 
+// Use of the following macros (error_impossible, error_if, and
+// error_unless) is discouraged.  All of these will only display a
+// generic error of the form
+//
+//   impossible state reached in file 'FILE' at line 'N'
+//
+// If the state really is "impossible" to reach, then it is better to
+// use one of the corresponding panic* functions instead (see panic.h).
+//
+// See also the discussion here: https://octave.discourse.group/t/assert-panic-error-and-ndebug/5409
+
 #define error_impossible()                                              \
   ::error ("impossible state reached in file '%s' at line %d", __FILE__, __LINE__)
 
-#if defined (NDEBUG)
-#  define error_if(cond)
-#else
-#  define error_if(cond) do { if (cond) error_impossible (); } while (0)
-#endif
+#define error_if(cond) do { if (cond) error_impossible (); } while (0)
 
-#if defined (NDEBUG)
-#  define error_unless(cond)
-#else
-#  define error_unless(cond) error_if (! (cond))
-#endif
+#define error_unless(cond) error_if (! (cond))
 
 OCTAVE_BEGIN_NAMESPACE(octave)