xapian-core  2.0.0
attributes.h
Go to the documentation of this file.
1 
4 // Copyright (C) 2012,2013,2014,2015,2017 Olly Betts
5 //
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 2 of the License, or
9 // (at your option) any later version.
10 //
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.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, see
18 // <https://www.gnu.org/licenses/>.
19 
20 #ifndef XAPIAN_INCLUDED_ATTRIBUTES_H
21 #define XAPIAN_INCLUDED_ATTRIBUTES_H
22 
23 #ifdef __GNUC__
24 
25 // __attribute__((__const__)) is available at least as far back as GCC 2.95.
26 # define XAPIAN_CONST_FUNCTION __attribute__((__const__))
27 // __attribute__((__pure__)) is available from GCC 2.96 onwards.
28 # define XAPIAN_PURE_FUNCTION __attribute__((__pure__))
29 
30 // We don't enable XAPIAN_NONNULL when building the library because that
31 // results in warnings when we check the parameter really isn't NULL, and we
32 // ought to still do that as (a) not all compilers support such annotations,
33 // and (b) even those that do don't actually prevent you from passing NULL.
34 # ifndef XAPIAN_LIB_BUILD
35 // __attribute__((__nonnull__(a,b,c))) is available from GCC 3.3 onwards, but
36 // seems to be buggy in GCC 4.8 so only enable it for versions after that.
37 // It's also supported by clang, which we have to check for separately as
38 // current versions pretend to be GCC 4.2.
39 # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 8) || \
40  defined __clang__
41 # define XAPIAN_NONNULL(LIST) __attribute__((__nonnull__ LIST))
42 # endif
43 # endif
44 
45 #else
46 
54 # define XAPIAN_CONST_FUNCTION
55 
59 # define XAPIAN_PURE_FUNCTION
60 
61 #endif
62 
63 #ifndef XAPIAN_NONNULL
84 # define XAPIAN_NONNULL(LIST)
85 #endif
86 
87 #endif // XAPIAN_INCLUDED_ATTRIBUTES_H