[patch rfc] Gag gdb_assert related const condition warning
Andrew Cagney
ac131313@redhat.com
Thu May 29 21:23:00 GMT 2003
> 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.
I've checked this in.
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 */
More information about the Gdb-patches
mailing list