Merged with mainline at revision 128810.
[official-gcc.git] / libstdc++-v3 / include / debug / debug.h
blobd488f1587d892c7ae55a14103ab682d9cdb6a246
1 // Debugging support implementation -*- C++ -*-
3 // Copyright (C) 2003, 2004, 2005, 2006, 2007
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
31 /** @file debug/debug.h
32 * This file is a GNU debug extension to the Standard C++ Library.
35 #ifndef _GLIBCXX_DEBUG_MACRO_SWITCH_H
36 #define _GLIBCXX_DEBUG_MACRO_SWITCH_H 1
38 /** Macros and namespaces used by the implementation outside of debug
39 * wrappers to verify certain properties. The __glibcxx_requires_xxx
40 * macros are merely wrappers around the __glibcxx_check_xxx wrappers
41 * when we are compiling with debug mode, but disappear when we are
42 * in release mode so that there is no checking performed in, e.g.,
43 * the standard library algorithms.
46 // Debug mode namespaces.
47 namespace std
49 namespace __debug { }
52 namespace __gnu_cxx
54 namespace __debug { };
57 namespace __gnu_debug
59 using namespace std::__debug;
60 using namespace __gnu_cxx::__debug;
63 #ifndef _GLIBCXX_DEBUG
65 # define _GLIBCXX_DEBUG_ASSERT(_Condition)
66 # define _GLIBCXX_DEBUG_PEDASSERT(_Condition)
67 # define _GLIBCXX_DEBUG_ONLY(_Statement) ;
68 # define __glibcxx_requires_cond(_Cond,_Msg)
69 # define __glibcxx_requires_valid_range(_First,_Last)
70 # define __glibcxx_requires_sorted(_First,_Last)
71 # define __glibcxx_requires_sorted_pred(_First,_Last,_Pred)
72 # define __glibcxx_requires_partitioned(_First,_Last,_Value)
73 # define __glibcxx_requires_partitioned_pred(_First,_Last,_Value,_Pred)
74 # define __glibcxx_requires_heap(_First,_Last)
75 # define __glibcxx_requires_heap_pred(_First,_Last,_Pred)
76 # define __glibcxx_requires_nonempty()
77 # define __glibcxx_requires_string(_String)
78 # define __glibcxx_requires_string_len(_String,_Len)
79 # define __glibcxx_requires_subscript(_N)
81 #else
83 # include <cstdio>
84 # include <debug/macros.h>
86 namespace std
88 namespace __debug
90 // Avoid the use of assert, because we're trying to keep the <cassert>
91 // include out of the mix.
92 inline void
93 __replacement_assert(const char* __file, int __line,
94 const char* __function, const char* __condition)
96 printf("%s:%d: %s: Assertion '%s' failed.\n", __file, __line,
97 __function, __condition);
98 __builtin_abort();
100 } // namespace __debug
101 } // namespace std
103 #define _GLIBCXX_DEBUG_ASSERT(_Condition) \
104 do \
106 if (! (_Condition)) \
107 std::__debug::__replacement_assert(__FILE__, __LINE__, \
108 __PRETTY_FUNCTION__, #_Condition); \
109 } while (false)
111 #ifdef _GLIBCXX_DEBUG_PEDANTIC
112 # define _GLIBCXX_DEBUG_PEDASSERT(_Condition) _GLIBCXX_DEBUG_ASSERT(_Condition)
113 #else
114 # define _GLIBCXX_DEBUG_PEDASSERT(_Condition)
115 #endif
117 # define _GLIBCXX_DEBUG_ONLY(_Statement) _Statement
119 # define __glibcxx_requires_cond(_Cond,_Msg) _GLIBCXX_DEBUG_VERIFY(_Cond,_Msg)
120 # define __glibcxx_requires_valid_range(_First,_Last) \
121 __glibcxx_check_valid_range(_First,_Last)
122 # define __glibcxx_requires_sorted(_First,_Last) \
123 __glibcxx_check_sorted(_First,_Last)
124 # define __glibcxx_requires_sorted_pred(_First,_Last,_Pred) \
125 __glibcxx_check_sorted_pred(_First,_Last,_Pred)
126 # define __glibcxx_requires_partitioned(_First,_Last,_Value) \
127 __glibcxx_check_partitioned(_First,_Last,_Value)
128 # define __glibcxx_requires_partitioned_pred(_First,_Last,_Value,_Pred) \
129 __glibcxx_check_partitioned_pred(_First,_Last,_Value,_Pred)
130 # define __glibcxx_requires_heap(_First,_Last) \
131 __glibcxx_check_heap(_First,_Last)
132 # define __glibcxx_requires_heap_pred(_First,_Last,_Pred) \
133 __glibcxx_check_heap_pred(_First,_Last,_Pred)
134 # define __glibcxx_requires_nonempty() __glibcxx_check_nonempty()
135 # define __glibcxx_requires_string(_String) __glibcxx_check_string(_String)
136 # define __glibcxx_requires_string_len(_String,_Len) \
137 __glibcxx_check_string_len(_String,_Len)
138 # define __glibcxx_requires_subscript(_N) __glibcxx_check_subscript(_N)
140 # include <debug/functions.h>
141 # include <debug/formatter.h>
143 #endif
145 #endif // _GLIBCXX_DEBUG_MACRO_SWITCH_H