This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch rfc] Gag gdb_assert related const condition warning


Hello,

Given an ISO C compiler that doesn't provide __FUNCTION__ or equivalent (e.g., IRIX CC) gdb_assert would end up expanding into something like:

	!(expr) ? 0 :
		internal_error (__FILE__, __LINE__, "%s%sAssert %s",
			0 ? 0 : "", 0 ? ": ", "", #expr);

and the fact that the conditional expressions were both constant would irritate some compilers (issuing a warning, again IRIX ...). The attached changes things so that the warning is no longer generated.

I'm motivated to do this because the IRIX compiler does issue other useful warnings but the above was swamping things :-/

Thoughts?

Baring objection, I'll commit in a few days.
Andrew
2003-05-23  Andrew Cagney  <cagney@redhat.com>

	* gdb_assert.h (gdb_assert_fail): Provide different definitions
	dependant on the availability of ASSERT_FUNCTION.
	(ASSERT_FUNCTION): Do not define when there is no function name.

Index: gdb_assert.h
===================================================================
RCS file: /cvs/src/src/gdb/gdb_assert.h,v
retrieving revision 1.3
diff -u -r1.3 gdb_assert.h
--- gdb_assert.h	1 Mar 2001 17:30:05 -0000	1.3
+++ gdb_assert.h	23 May 2003 17:22:20 -0000
@@ -40,16 +40,19 @@
 #else
 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
 #define ASSERT_FUNCTION		__func__
-#else
-#define ASSERT_FUNCTION		((const char *) 0)
 #endif
 #endif
 
 /* This prints an "Assertion failed" message, aksing the user if they
    want to continue, dump core, or just exit.  */
+#if defined (ASSERT_FUNCTION)
+#define gdb_assert_fail(assertion, file, line, function)                      \
+  internal_error (file, line, "%s: Assertion `%s' failed.",                   \
+		  function, assertion)
+#else
 #define gdb_assert_fail(assertion, file, line, function)                      \
-  internal_error (file, line, "%s%sAssertion `%s' failed.",                   \
-		  function ? function : "", function ? ": " : "",             \
+  internal_error (file, line, "Assertion `%s' failed.",                       \
 		  assertion)
+#endif
 
 #endif /* gdb_assert.h */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]