xapian-core  1.4.26
attributes.h
Go to the documentation of this file.
1 
4 // Copyright (C) 2012,2013,2014,2015 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, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 #ifndef XAPIAN_INCLUDED_ATTRIBUTES_H
21 #define XAPIAN_INCLUDED_ATTRIBUTES_H
22 
23 #if __cplusplus >= 201103L || (defined _MSC_VER && _MSC_VER >= 1900)
24 // C++11 has noexcept for marking a function which shouldn't throw.
25 //
26 // You need a C++11 compiler to build Xapian, but we still support using a
27 // non-C++11 compiler to build code which uses Xapian (one reason is that
28 // currently you need an option to enable C++11 support for most
29 // compilers). Once we require C++11 for using Xapian, XAPIAN_NOTHROW can go
30 // away.
31 //
32 // We can't simply just add noexcept via XAPIAN_NOTHROW as noexcept has
33 // to be added to all declarations, whereas the GCC attribute can't be used on
34 // a function definition. So for now, XAPIAN_NOTHROW() goes around
35 // declarations, and XAPIAN_NOEXCEPT needs to be explicitly added to
36 // definitions.
37 # define XAPIAN_NOEXCEPT noexcept
38 #else
39 # define XAPIAN_NOEXCEPT
40 #endif
41 
42 #ifdef __GNUC__
43 
44 // __attribute__((__const__)) is available at least as far back as GCC 2.95.
45 # define XAPIAN_CONST_FUNCTION __attribute__((__const__))
46 // __attribute__((__pure__)) is available from GCC 2.96 onwards.
47 # define XAPIAN_PURE_FUNCTION __attribute__((__pure__))
48 // __attribute__((__nothrow__)) is available from GCC 3.3 onwards.
49 # if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
50 # define XAPIAN_NOTHROW(D) D XAPIAN_NOEXCEPT __attribute__((__nothrow__))
51 # endif
52 
53 #else
54 
62 # define XAPIAN_CONST_FUNCTION
63 
67 # define XAPIAN_PURE_FUNCTION
68 
69 #endif
70 
71 #ifndef XAPIAN_NOTHROW
72 
73 # define XAPIAN_NOTHROW(D) D XAPIAN_NOEXCEPT
74 #endif
75 
76 #endif // XAPIAN_INCLUDED_ATTRIBUTES_H