xref: /dflybsd-src/contrib/binutils-2.34/include/ansidecl.h (revision b52ef7118d1621abed722c5bbbd542210290ecef)
1*fae548d3Szrj /* ANSI and traditional C compatability macros
2*fae548d3Szrj    Copyright (C) 1991-2020 Free Software Foundation, Inc.
3*fae548d3Szrj    This file is part of the GNU C Library.
4*fae548d3Szrj 
5*fae548d3Szrj This program is free software; you can redistribute it and/or modify
6*fae548d3Szrj it under the terms of the GNU General Public License as published by
7*fae548d3Szrj the Free Software Foundation; either version 2 of the License, or
8*fae548d3Szrj (at your option) any later version.
9*fae548d3Szrj 
10*fae548d3Szrj This program is distributed in the hope that it will be useful,
11*fae548d3Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of
12*fae548d3Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*fae548d3Szrj GNU General Public License for more details.
14*fae548d3Szrj 
15*fae548d3Szrj You should have received a copy of the GNU General Public License
16*fae548d3Szrj along with this program; if not, write to the Free Software
17*fae548d3Szrj Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
18*fae548d3Szrj 
19*fae548d3Szrj /* ANSI and traditional C compatibility macros
20*fae548d3Szrj 
21*fae548d3Szrj    ANSI C is assumed if __STDC__ is #defined.
22*fae548d3Szrj 
23*fae548d3Szrj    Macro		ANSI C definition	Traditional C definition
24*fae548d3Szrj    -----		---- - ----------	----------- - ----------
25*fae548d3Szrj    PTR			`void *'		`char *'
26*fae548d3Szrj    const		not defined		`'
27*fae548d3Szrj    volatile		not defined		`'
28*fae548d3Szrj    signed		not defined		`'
29*fae548d3Szrj 
30*fae548d3Szrj    For ease of writing code which uses GCC extensions but needs to be
31*fae548d3Szrj    portable to other compilers, we provide the GCC_VERSION macro that
32*fae548d3Szrj    simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
33*fae548d3Szrj    wrappers around __attribute__.  Also, __extension__ will be #defined
34*fae548d3Szrj    to nothing if it doesn't work.  See below.  */
35*fae548d3Szrj 
36*fae548d3Szrj #ifndef	_ANSIDECL_H
37*fae548d3Szrj #define _ANSIDECL_H	1
38*fae548d3Szrj 
39*fae548d3Szrj #ifdef __cplusplus
40*fae548d3Szrj extern "C" {
41*fae548d3Szrj #endif
42*fae548d3Szrj 
43*fae548d3Szrj /* Every source file includes this file,
44*fae548d3Szrj    so they will all get the switch for lint.  */
45*fae548d3Szrj /* LINTLIBRARY */
46*fae548d3Szrj 
47*fae548d3Szrj /* Using MACRO(x,y) in cpp #if conditionals does not work with some
48*fae548d3Szrj    older preprocessors.  Thus we can't define something like this:
49*fae548d3Szrj 
50*fae548d3Szrj #define HAVE_GCC_VERSION(MAJOR, MINOR) \
51*fae548d3Szrj   (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR)))
52*fae548d3Szrj 
53*fae548d3Szrj and then test "#if HAVE_GCC_VERSION(2,7)".
54*fae548d3Szrj 
55*fae548d3Szrj So instead we use the macro below and test it against specific values.  */
56*fae548d3Szrj 
57*fae548d3Szrj /* This macro simplifies testing whether we are using gcc, and if it
58*fae548d3Szrj    is of a particular minimum version. (Both major & minor numbers are
59*fae548d3Szrj    significant.)  This macro will evaluate to 0 if we are not using
60*fae548d3Szrj    gcc at all.  */
61*fae548d3Szrj #ifndef GCC_VERSION
62*fae548d3Szrj #define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
63*fae548d3Szrj #endif /* GCC_VERSION */
64*fae548d3Szrj 
65*fae548d3Szrj #if defined (__STDC__) || defined(__cplusplus) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32)
66*fae548d3Szrj /* All known AIX compilers implement these things (but don't always
67*fae548d3Szrj    define __STDC__).  The RISC/OS MIPS compiler defines these things
68*fae548d3Szrj    in SVR4 mode, but does not define __STDC__.  */
69*fae548d3Szrj /* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other
70*fae548d3Szrj    C++ compilers, does not define __STDC__, though it acts as if this
71*fae548d3Szrj    was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */
72*fae548d3Szrj 
73*fae548d3Szrj #define PTR		void *
74*fae548d3Szrj 
75*fae548d3Szrj #undef const
76*fae548d3Szrj #undef volatile
77*fae548d3Szrj #undef signed
78*fae548d3Szrj 
79*fae548d3Szrj /* inline requires special treatment; it's in C99, and GCC >=2.7 supports
80*fae548d3Szrj    it too, but it's not in C89.  */
81*fae548d3Szrj #undef inline
82*fae548d3Szrj #if __STDC_VERSION__ >= 199901L || defined(__cplusplus) || (defined(__SUNPRO_C) && defined(__C99FEATURES__))
83*fae548d3Szrj /* it's a keyword */
84*fae548d3Szrj #else
85*fae548d3Szrj # if GCC_VERSION >= 2007
86*fae548d3Szrj #  define inline __inline__   /* __inline__ prevents -pedantic warnings */
87*fae548d3Szrj # else
88*fae548d3Szrj #  define inline  /* nothing */
89*fae548d3Szrj # endif
90*fae548d3Szrj #endif
91*fae548d3Szrj 
92*fae548d3Szrj #else	/* Not ANSI C.  */
93*fae548d3Szrj 
94*fae548d3Szrj #define PTR		char *
95*fae548d3Szrj 
96*fae548d3Szrj /* some systems define these in header files for non-ansi mode */
97*fae548d3Szrj #undef const
98*fae548d3Szrj #undef volatile
99*fae548d3Szrj #undef signed
100*fae548d3Szrj #undef inline
101*fae548d3Szrj #define const
102*fae548d3Szrj #define volatile
103*fae548d3Szrj #define signed
104*fae548d3Szrj #define inline
105*fae548d3Szrj 
106*fae548d3Szrj #endif	/* ANSI C.  */
107*fae548d3Szrj 
108*fae548d3Szrj /* Define macros for some gcc attributes.  This permits us to use the
109*fae548d3Szrj    macros freely, and know that they will come into play for the
110*fae548d3Szrj    version of gcc in which they are supported.  */
111*fae548d3Szrj 
112*fae548d3Szrj #if (GCC_VERSION < 2007)
113*fae548d3Szrj # define __attribute__(x)
114*fae548d3Szrj #endif
115*fae548d3Szrj 
116*fae548d3Szrj /* Attribute __malloc__ on functions was valid as of gcc 2.96. */
117*fae548d3Szrj #ifndef ATTRIBUTE_MALLOC
118*fae548d3Szrj # if (GCC_VERSION >= 2096)
119*fae548d3Szrj #  define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
120*fae548d3Szrj # else
121*fae548d3Szrj #  define ATTRIBUTE_MALLOC
122*fae548d3Szrj # endif /* GNUC >= 2.96 */
123*fae548d3Szrj #endif /* ATTRIBUTE_MALLOC */
124*fae548d3Szrj 
125*fae548d3Szrj /* Attributes on labels were valid as of gcc 2.93 and g++ 4.5.  For
126*fae548d3Szrj    g++ an attribute on a label must be followed by a semicolon.  */
127*fae548d3Szrj #ifndef ATTRIBUTE_UNUSED_LABEL
128*fae548d3Szrj # ifndef __cplusplus
129*fae548d3Szrj #  if GCC_VERSION >= 2093
130*fae548d3Szrj #   define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
131*fae548d3Szrj #  else
132*fae548d3Szrj #   define ATTRIBUTE_UNUSED_LABEL
133*fae548d3Szrj #  endif
134*fae548d3Szrj # else
135*fae548d3Szrj #  if GCC_VERSION >= 4005
136*fae548d3Szrj #   define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED ;
137*fae548d3Szrj #  else
138*fae548d3Szrj #   define ATTRIBUTE_UNUSED_LABEL
139*fae548d3Szrj #  endif
140*fae548d3Szrj # endif
141*fae548d3Szrj #endif
142*fae548d3Szrj 
143*fae548d3Szrj /* Similarly to ARG_UNUSED below.  Prior to GCC 3.4, the C++ frontend
144*fae548d3Szrj    couldn't parse attributes placed after the identifier name, and now
145*fae548d3Szrj    the entire compiler is built with C++.  */
146*fae548d3Szrj #ifndef ATTRIBUTE_UNUSED
147*fae548d3Szrj #if GCC_VERSION >= 3004
148*fae548d3Szrj #  define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
149*fae548d3Szrj #else
150*fae548d3Szrj #define ATTRIBUTE_UNUSED
151*fae548d3Szrj #endif
152*fae548d3Szrj #endif /* ATTRIBUTE_UNUSED */
153*fae548d3Szrj 
154*fae548d3Szrj /* Before GCC 3.4, the C++ frontend couldn't parse attributes placed after the
155*fae548d3Szrj    identifier name.  */
156*fae548d3Szrj #if ! defined(__cplusplus) || (GCC_VERSION >= 3004)
157*fae548d3Szrj # define ARG_UNUSED(NAME) NAME ATTRIBUTE_UNUSED
158*fae548d3Szrj #else /* !__cplusplus || GNUC >= 3.4 */
159*fae548d3Szrj # define ARG_UNUSED(NAME) NAME
160*fae548d3Szrj #endif /* !__cplusplus || GNUC >= 3.4 */
161*fae548d3Szrj 
162*fae548d3Szrj #ifndef ATTRIBUTE_NORETURN
163*fae548d3Szrj #define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
164*fae548d3Szrj #endif /* ATTRIBUTE_NORETURN */
165*fae548d3Szrj 
166*fae548d3Szrj /* Attribute `nonnull' was valid as of gcc 3.3.  */
167*fae548d3Szrj #ifndef ATTRIBUTE_NONNULL
168*fae548d3Szrj # if (GCC_VERSION >= 3003)
169*fae548d3Szrj #  define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
170*fae548d3Szrj # else
171*fae548d3Szrj #  define ATTRIBUTE_NONNULL(m)
172*fae548d3Szrj # endif /* GNUC >= 3.3 */
173*fae548d3Szrj #endif /* ATTRIBUTE_NONNULL */
174*fae548d3Szrj 
175*fae548d3Szrj /* Attribute `returns_nonnull' was valid as of gcc 4.9.  */
176*fae548d3Szrj #ifndef ATTRIBUTE_RETURNS_NONNULL
177*fae548d3Szrj # if (GCC_VERSION >= 4009)
178*fae548d3Szrj #  define ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
179*fae548d3Szrj # else
180*fae548d3Szrj #  define ATTRIBUTE_RETURNS_NONNULL
181*fae548d3Szrj # endif /* GNUC >= 4.9 */
182*fae548d3Szrj #endif /* ATTRIBUTE_RETURNS_NONNULL */
183*fae548d3Szrj 
184*fae548d3Szrj /* Attribute `pure' was valid as of gcc 3.0.  */
185*fae548d3Szrj #ifndef ATTRIBUTE_PURE
186*fae548d3Szrj # if (GCC_VERSION >= 3000)
187*fae548d3Szrj #  define ATTRIBUTE_PURE __attribute__ ((__pure__))
188*fae548d3Szrj # else
189*fae548d3Szrj #  define ATTRIBUTE_PURE
190*fae548d3Szrj # endif /* GNUC >= 3.0 */
191*fae548d3Szrj #endif /* ATTRIBUTE_PURE */
192*fae548d3Szrj 
193*fae548d3Szrj /* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL.
194*fae548d3Szrj    This was the case for the `printf' format attribute by itself
195*fae548d3Szrj    before GCC 3.3, but as of 3.3 we need to add the `nonnull'
196*fae548d3Szrj    attribute to retain this behavior.  */
197*fae548d3Szrj #ifndef ATTRIBUTE_PRINTF
198*fae548d3Szrj #define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m)
199*fae548d3Szrj #define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)
200*fae548d3Szrj #define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
201*fae548d3Szrj #define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4)
202*fae548d3Szrj #define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5)
203*fae548d3Szrj #define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6)
204*fae548d3Szrj #endif /* ATTRIBUTE_PRINTF */
205*fae548d3Szrj 
206*fae548d3Szrj /* Use ATTRIBUTE_FPTR_PRINTF when the format attribute is to be set on
207*fae548d3Szrj    a function pointer.  Format attributes were allowed on function
208*fae548d3Szrj    pointers as of gcc 3.1.  */
209*fae548d3Szrj #ifndef ATTRIBUTE_FPTR_PRINTF
210*fae548d3Szrj # if (GCC_VERSION >= 3001)
211*fae548d3Szrj #  define ATTRIBUTE_FPTR_PRINTF(m, n) ATTRIBUTE_PRINTF(m, n)
212*fae548d3Szrj # else
213*fae548d3Szrj #  define ATTRIBUTE_FPTR_PRINTF(m, n)
214*fae548d3Szrj # endif /* GNUC >= 3.1 */
215*fae548d3Szrj # define ATTRIBUTE_FPTR_PRINTF_1 ATTRIBUTE_FPTR_PRINTF(1, 2)
216*fae548d3Szrj # define ATTRIBUTE_FPTR_PRINTF_2 ATTRIBUTE_FPTR_PRINTF(2, 3)
217*fae548d3Szrj # define ATTRIBUTE_FPTR_PRINTF_3 ATTRIBUTE_FPTR_PRINTF(3, 4)
218*fae548d3Szrj # define ATTRIBUTE_FPTR_PRINTF_4 ATTRIBUTE_FPTR_PRINTF(4, 5)
219*fae548d3Szrj # define ATTRIBUTE_FPTR_PRINTF_5 ATTRIBUTE_FPTR_PRINTF(5, 6)
220*fae548d3Szrj #endif /* ATTRIBUTE_FPTR_PRINTF */
221*fae548d3Szrj 
222*fae548d3Szrj /* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL.  A
223*fae548d3Szrj    NULL format specifier was allowed as of gcc 3.3.  */
224*fae548d3Szrj #ifndef ATTRIBUTE_NULL_PRINTF
225*fae548d3Szrj # if (GCC_VERSION >= 3003)
226*fae548d3Szrj #  define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
227*fae548d3Szrj # else
228*fae548d3Szrj #  define ATTRIBUTE_NULL_PRINTF(m, n)
229*fae548d3Szrj # endif /* GNUC >= 3.3 */
230*fae548d3Szrj # define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2)
231*fae548d3Szrj # define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3)
232*fae548d3Szrj # define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4)
233*fae548d3Szrj # define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5)
234*fae548d3Szrj # define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6)
235*fae548d3Szrj #endif /* ATTRIBUTE_NULL_PRINTF */
236*fae548d3Szrj 
237*fae548d3Szrj /* Attribute `sentinel' was valid as of gcc 3.5.  */
238*fae548d3Szrj #ifndef ATTRIBUTE_SENTINEL
239*fae548d3Szrj # if (GCC_VERSION >= 3005)
240*fae548d3Szrj #  define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__))
241*fae548d3Szrj # else
242*fae548d3Szrj #  define ATTRIBUTE_SENTINEL
243*fae548d3Szrj # endif /* GNUC >= 3.5 */
244*fae548d3Szrj #endif /* ATTRIBUTE_SENTINEL */
245*fae548d3Szrj 
246*fae548d3Szrj 
247*fae548d3Szrj #ifndef ATTRIBUTE_ALIGNED_ALIGNOF
248*fae548d3Szrj # if (GCC_VERSION >= 3000)
249*fae548d3Szrj #  define ATTRIBUTE_ALIGNED_ALIGNOF(m) __attribute__ ((__aligned__ (__alignof__ (m))))
250*fae548d3Szrj # else
251*fae548d3Szrj #  define ATTRIBUTE_ALIGNED_ALIGNOF(m)
252*fae548d3Szrj # endif /* GNUC >= 3.0 */
253*fae548d3Szrj #endif /* ATTRIBUTE_ALIGNED_ALIGNOF */
254*fae548d3Szrj 
255*fae548d3Szrj /* Useful for structures whose layout must match some binary specification
256*fae548d3Szrj    regardless of the alignment and padding qualities of the compiler.  */
257*fae548d3Szrj #ifndef ATTRIBUTE_PACKED
258*fae548d3Szrj # define ATTRIBUTE_PACKED __attribute__ ((packed))
259*fae548d3Szrj #endif
260*fae548d3Szrj 
261*fae548d3Szrj /* Attribute `hot' and `cold' was valid as of gcc 4.3.  */
262*fae548d3Szrj #ifndef ATTRIBUTE_COLD
263*fae548d3Szrj # if (GCC_VERSION >= 4003)
264*fae548d3Szrj #  define ATTRIBUTE_COLD __attribute__ ((__cold__))
265*fae548d3Szrj # else
266*fae548d3Szrj #  define ATTRIBUTE_COLD
267*fae548d3Szrj # endif /* GNUC >= 4.3 */
268*fae548d3Szrj #endif /* ATTRIBUTE_COLD */
269*fae548d3Szrj #ifndef ATTRIBUTE_HOT
270*fae548d3Szrj # if (GCC_VERSION >= 4003)
271*fae548d3Szrj #  define ATTRIBUTE_HOT __attribute__ ((__hot__))
272*fae548d3Szrj # else
273*fae548d3Szrj #  define ATTRIBUTE_HOT
274*fae548d3Szrj # endif /* GNUC >= 4.3 */
275*fae548d3Szrj #endif /* ATTRIBUTE_HOT */
276*fae548d3Szrj 
277*fae548d3Szrj /* Attribute 'no_sanitize_undefined' was valid as of gcc 4.9.  */
278*fae548d3Szrj #ifndef ATTRIBUTE_NO_SANITIZE_UNDEFINED
279*fae548d3Szrj # if (GCC_VERSION >= 4009)
280*fae548d3Szrj #  define ATTRIBUTE_NO_SANITIZE_UNDEFINED __attribute__ ((no_sanitize_undefined))
281*fae548d3Szrj # else
282*fae548d3Szrj #  define ATTRIBUTE_NO_SANITIZE_UNDEFINED
283*fae548d3Szrj # endif /* GNUC >= 4.9 */
284*fae548d3Szrj #endif /* ATTRIBUTE_NO_SANITIZE_UNDEFINED */
285*fae548d3Szrj 
286*fae548d3Szrj /* Attribute 'nonstring' was valid as of gcc 8.  */
287*fae548d3Szrj #ifndef ATTRIBUTE_NONSTRING
288*fae548d3Szrj # if GCC_VERSION >= 8000
289*fae548d3Szrj #  define ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
290*fae548d3Szrj # else
291*fae548d3Szrj #  define ATTRIBUTE_NONSTRING
292*fae548d3Szrj # endif
293*fae548d3Szrj #endif
294*fae548d3Szrj 
295*fae548d3Szrj /* Attribute `alloc_size' was valid as of gcc 4.3.  */
296*fae548d3Szrj #ifndef ATTRIBUTE_RESULT_SIZE_1
297*fae548d3Szrj # if (GCC_VERSION >= 4003)
298*fae548d3Szrj #  define ATTRIBUTE_RESULT_SIZE_1 __attribute__ ((alloc_size (1)))
299*fae548d3Szrj # else
300*fae548d3Szrj #  define ATTRIBUTE_RESULT_SIZE_1
301*fae548d3Szrj #endif
302*fae548d3Szrj #endif
303*fae548d3Szrj 
304*fae548d3Szrj #ifndef ATTRIBUTE_RESULT_SIZE_2
305*fae548d3Szrj # if (GCC_VERSION >= 4003)
306*fae548d3Szrj #  define ATTRIBUTE_RESULT_SIZE_2 __attribute__ ((alloc_size (2)))
307*fae548d3Szrj # else
308*fae548d3Szrj #  define ATTRIBUTE_RESULT_SIZE_2
309*fae548d3Szrj #endif
310*fae548d3Szrj #endif
311*fae548d3Szrj 
312*fae548d3Szrj #ifndef ATTRIBUTE_RESULT_SIZE_1_2
313*fae548d3Szrj # if (GCC_VERSION >= 4003)
314*fae548d3Szrj #  define ATTRIBUTE_RESULT_SIZE_1_2 __attribute__ ((alloc_size (1, 2)))
315*fae548d3Szrj # else
316*fae548d3Szrj #  define ATTRIBUTE_RESULT_SIZE_1_2
317*fae548d3Szrj #endif
318*fae548d3Szrj #endif
319*fae548d3Szrj 
320*fae548d3Szrj /* Attribute `warn_unused_result' was valid as of gcc 3.3.  */
321*fae548d3Szrj #ifndef ATTRIBUTE_WARN_UNUSED_RESULT
322*fae548d3Szrj # if GCC_VERSION >= 3003
323*fae548d3Szrj #  define ATTRIBUTE_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
324*fae548d3Szrj # else
325*fae548d3Szrj #  define ATTRIBUTE_WARN_UNUSED_RESULT
326*fae548d3Szrj # endif
327*fae548d3Szrj #endif
328*fae548d3Szrj 
329*fae548d3Szrj /* We use __extension__ in some places to suppress -pedantic warnings
330*fae548d3Szrj    about GCC extensions.  This feature didn't work properly before
331*fae548d3Szrj    gcc 2.8.  */
332*fae548d3Szrj #if GCC_VERSION < 2008
333*fae548d3Szrj #define __extension__
334*fae548d3Szrj #endif
335*fae548d3Szrj 
336*fae548d3Szrj /* This is used to declare a const variable which should be visible
337*fae548d3Szrj    outside of the current compilation unit.  Use it as
338*fae548d3Szrj      EXPORTED_CONST int i = 1;
339*fae548d3Szrj    This is because the semantics of const are different in C and C++.
340*fae548d3Szrj    "extern const" is permitted in C but it looks strange, and gcc
341*fae548d3Szrj    warns about it when -Wc++-compat is not used.  */
342*fae548d3Szrj #ifdef __cplusplus
343*fae548d3Szrj #define EXPORTED_CONST extern const
344*fae548d3Szrj #else
345*fae548d3Szrj #define EXPORTED_CONST const
346*fae548d3Szrj #endif
347*fae548d3Szrj 
348*fae548d3Szrj /* Be conservative and only use enum bitfields with C++ or GCC.
349*fae548d3Szrj    FIXME: provide a complete autoconf test for buggy enum bitfields.  */
350*fae548d3Szrj 
351*fae548d3Szrj #ifdef __cplusplus
352*fae548d3Szrj #define ENUM_BITFIELD(TYPE) enum TYPE
353*fae548d3Szrj #elif (GCC_VERSION > 2000)
354*fae548d3Szrj #define ENUM_BITFIELD(TYPE) __extension__ enum TYPE
355*fae548d3Szrj #else
356*fae548d3Szrj #define ENUM_BITFIELD(TYPE) unsigned int
357*fae548d3Szrj #endif
358*fae548d3Szrj 
359*fae548d3Szrj #if __cpp_constexpr >= 200704
360*fae548d3Szrj #define CONSTEXPR constexpr
361*fae548d3Szrj #else
362*fae548d3Szrj #define CONSTEXPR
363*fae548d3Szrj #endif
364*fae548d3Szrj 
365*fae548d3Szrj /* C++11 adds the ability to add "override" after an implementation of a
366*fae548d3Szrj    virtual function in a subclass, to:
367*fae548d3Szrj      (A) document that this is an override of a virtual function
368*fae548d3Szrj      (B) allow the compiler to issue a warning if it isn't (e.g. a mismatch
369*fae548d3Szrj          of the type signature).
370*fae548d3Szrj 
371*fae548d3Szrj    Similarly, it allows us to add a "final" to indicate that no subclass
372*fae548d3Szrj    may subsequently override the vfunc.
373*fae548d3Szrj 
374*fae548d3Szrj    Provide OVERRIDE and FINAL as macros, allowing us to get these benefits
375*fae548d3Szrj    when compiling with C++11 support, but without requiring C++11.
376*fae548d3Szrj 
377*fae548d3Szrj    For gcc, use "-std=c++11" to enable C++11 support; gcc 6 onwards enables
378*fae548d3Szrj    this by default (actually GNU++14).  */
379*fae548d3Szrj 
380*fae548d3Szrj #if defined __cplusplus
381*fae548d3Szrj # if __cplusplus >= 201103
382*fae548d3Szrj    /* C++11 claims to be available: use it.  Final/override were only
383*fae548d3Szrj       implemented in 4.7, though.  */
384*fae548d3Szrj #  if GCC_VERSION < 4007
385*fae548d3Szrj #   define OVERRIDE
386*fae548d3Szrj #   define FINAL
387*fae548d3Szrj #  else
388*fae548d3Szrj #   define OVERRIDE override
389*fae548d3Szrj #   define FINAL final
390*fae548d3Szrj #  endif
391*fae548d3Szrj # elif GCC_VERSION >= 4007
392*fae548d3Szrj    /* G++ 4.7 supports __final in C++98.  */
393*fae548d3Szrj #  define OVERRIDE
394*fae548d3Szrj #  define FINAL __final
395*fae548d3Szrj # else
396*fae548d3Szrj    /* No C++11 support; leave the macros empty.  */
397*fae548d3Szrj #  define OVERRIDE
398*fae548d3Szrj #  define FINAL
399*fae548d3Szrj # endif
400*fae548d3Szrj #else
401*fae548d3Szrj   /* No C++11 support; leave the macros empty.  */
402*fae548d3Szrj # define OVERRIDE
403*fae548d3Szrj # define FINAL
404*fae548d3Szrj #endif
405*fae548d3Szrj 
406*fae548d3Szrj /* A macro to disable the copy constructor and assignment operator.
407*fae548d3Szrj    When building with C++11 and above, the methods are explicitly
408*fae548d3Szrj    deleted, causing a compile-time error if something tries to copy.
409*fae548d3Szrj    For C++03, this just declares the methods, causing a link-time
410*fae548d3Szrj    error if the methods end up called (assuming you don't
411*fae548d3Szrj    define them).  For C++03, for best results, place the macro
412*fae548d3Szrj    under the private: access specifier, like this,
413*fae548d3Szrj 
414*fae548d3Szrj    class name_lookup
415*fae548d3Szrj    {
416*fae548d3Szrj      private:
417*fae548d3Szrj        DISABLE_COPY_AND_ASSIGN (name_lookup);
418*fae548d3Szrj    };
419*fae548d3Szrj 
420*fae548d3Szrj    so that most attempts at copy are caught at compile-time.  */
421*fae548d3Szrj 
422*fae548d3Szrj #if __cplusplus >= 201103
423*fae548d3Szrj #define DISABLE_COPY_AND_ASSIGN(TYPE)		\
424*fae548d3Szrj   TYPE (const TYPE&) = delete;			\
425*fae548d3Szrj   void operator= (const TYPE &) = delete
426*fae548d3Szrj   #else
427*fae548d3Szrj #define DISABLE_COPY_AND_ASSIGN(TYPE)		\
428*fae548d3Szrj   TYPE (const TYPE&);				\
429*fae548d3Szrj   void operator= (const TYPE &)
430*fae548d3Szrj #endif /* __cplusplus >= 201103 */
431*fae548d3Szrj 
432*fae548d3Szrj #ifdef __cplusplus
433*fae548d3Szrj }
434*fae548d3Szrj #endif
435*fae548d3Szrj 
436*fae548d3Szrj #endif	/* ansidecl.h	*/
437