1 /* GDB-friendly replacement for <assert.h>.
2 Copyright (C) 2000-2013 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 /* A static assertion. This will cause a compile-time error if EXPR,
23 which must be a compile-time constant, is false. */
25 #define gdb_static_assert(expr) \
26 extern int never_defined_just_used_for_checking[(expr) ? 1 : -1]
28 /* PRAGMATICS: "gdb_assert.h":gdb_assert() is a lower case (rather
29 than upper case) macro since that provides the closest fit to the
30 existing lower case macro <assert.h>:assert() that it is
33 #define gdb_assert(expr) \
34 ((void) ((expr) ? 0 : \
35 (gdb_assert_fail (#expr, __FILE__, __LINE__, ASSERT_FUNCTION), 0)))
37 /* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
38 which contains the name of the function currently being defined.
39 This is broken in G++ before version 2.6.
40 C9x has a similar variable called __func__, but prefer the GCC one since
41 it demangles C++ function names. */
42 #if (GCC_VERSION >= 2004)
43 #define ASSERT_FUNCTION __PRETTY_FUNCTION__
45 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
46 #define ASSERT_FUNCTION __func__
50 /* This prints an "Assertion failed" message, asking the user if they
51 want to continue, dump core, or just exit. */
52 #if defined (ASSERT_FUNCTION)
53 #define gdb_assert_fail(assertion, file, line, function) \
54 internal_error (file, line, _("%s: Assertion `%s' failed."), \
57 #define gdb_assert_fail(assertion, file, line, function) \
58 internal_error (file, line, _("Assertion `%s' failed."), \
62 /* The canonical form of gdb_assert (0).
63 MESSAGE is a string to include in the error message. */
65 #if defined (ASSERT_FUNCTION)
66 #define gdb_assert_not_reached(message) \
67 internal_error (__FILE__, __LINE__, "%s: %s", ASSERT_FUNCTION, _(message))
69 #define gdb_assert_not_reached(message) \
70 internal_error (__FILE__, __LINE__, _(message))
73 #endif /* gdb_assert.h */
This page took 0.046162 seconds and 4 git commands to generate.