libpqxx  5.0
compiler-public.hxx
1 /*-------------------------------------------------------------------------
2  *
3  * FILE
4  * pqxx/compiler-public.hxx
5  *
6  * DESCRIPTION
7  * Compiler deficiency workarounds for libpqxx clients
8  *
9  * Copyright (c) 2002-2015, Jeroen T. Vermeulen <jtv@xs4all.nl>
10  *
11  * See COPYING for copyright license. If you did not receive a file called
12  * COPYING with this source code, please notify the distributor of this mistake,
13  * or contact the author.
14  *
15  *-------------------------------------------------------------------------
16  */
17 #ifndef PQXX_H_COMPILER_PUBLIC
18 #define PQXX_H_COMPILER_PUBLIC
19 
20 #ifdef PQXX_HAVE_BOOST_SMART_PTR
21 #include <boost/smart_ptr.hpp>
22 #endif
23 
24 #ifdef PQXX_HAVE_MOVE
25 #include <utility>
26 #define PQXX_MOVE(value) (std::move(value))
27 #else
28 #define PQXX_MOVE(value) (value)
29 #endif
30 
31 #ifdef PQXX_HAVE_NOEXCEPT
32 #define PQXX_NOEXCEPT noexcept
33 #else
34 #define PQXX_NOEXCEPT throw ()
35 #endif
36 
37 #ifdef PQXX_HAVE_DELETED_OP
38 #define PQXX_DELETED_OP =delete
39 #else
40 #define PQXX_DELETED_OP /* =delete */
41 #endif
42 
43 #ifdef PQXX_HAVE_OVERRIDE
44 #define PQXX_OVERRIDE override
45 #else
46 #define PQXX_OVERRIDE /*override*/
47 #endif
48 
49 #ifdef PQXX_HAVE_FINAL
50 #define PQXX_FINAL final
51 #else
52 #define PQXX_FINAL /*final*/
53 #endif
54 
55 #ifdef _MSC_VER
56 
57 /* Work around a particularly pernicious and deliberate bug in Visual C++:
58  * min() and max() are defined as macros, which can have some very nasty
59  * consequences. This compiler bug can be switched off by defining NOMINMAX.
60  *
61  * We don't like making choices for the user and defining environmental macros
62  * of our own accord, but in this case it's the only way to compile without
63  * incurring a significant risk of bugs--and there doesn't appear to be any
64  * downside. One wonders why this compiler wart is being maintained at all,
65  * since the introduction of inline functions back in the 20th century.
66  */
67 #if defined(min) || defined(max)
68 #error "Oops: min() and/or max() are defined as preprocessor macros.\
69  Define NOMINMAX macro before including any system headers!"
70 #endif
71 
72 #ifndef NOMINMAX
73 #define NOMINMAX
74 #endif
75 
76 // Suppress vtables on abstract classes.
77 #define PQXX_NOVTABLE __declspec(novtable)
78 
79 #endif // _MSC_VER
80 
81 
82 // Workarounds & definitions that need to be included even in library's headers
83 #include "pqxx/config-public-compiler.h"
84 
85 // Workarounds for SUN Workshop 6
86 #if defined(__SUNPRO_CC)
87 #if __SUNPRO_CC_COMPAT < 5
88 #error "This compiler version is not capable of building libpqxx."
89 #endif // __SUNPRO_CC_COMPAT < 5
90 #define PQXX_PRIVATE __hidden
91 #endif // __SUNPRO_CC
92 
93 
94 #if defined(__GNUC__) && defined(PQXX_HAVE_GCC_CONST)
95 #define PQXX_CONST __attribute__ ((const))
96 #else
97 #define PQXX_CONST
98 #endif
99 
100 #if defined(PQXX_HAVE_DEPRECATED)
101 #define PQXX_DEPRECATED [[deprecated]]
102 #elif defined(__GNUC__) && defined(PQXX_HAVE_GCC_DEPRECATED)
103 #define PQXX_DEPRECATED __attribute__ ((deprecated))
104 #else
105 #define PQXX_DEPRECATED
106 #endif
107 
108 #if defined(PQXX_HAVE_NORETURN)
109 #define PQXX_NORETURN [[noreturn]]
110 #elif defined(__GNUC__) && defined(PQXX_HAVE_GCC_NORETURN)
111 #define PQXX_NORETURN __attribute__ ((noreturn))
112 #elif defined(_MSC_VER)
113 #define PQXX_NORETURN _declspec(noreturn)
114 #else
115 #define PQXX_NORETURN
116 #endif
117 
118 #if defined(__GNUC__) && defined(PQXX_HAVE_GCC_PURE)
119 #define PQXX_PURE __attribute__ ((pure))
120 #else
121 #define PQXX_PURE
122 #endif
123 
124 
125 // Workarounds for Windows
126 #ifdef _WIN32
127 
128 
129 /* For now, export DLL symbols if _DLL is defined. This is done automatically
130  * by the compiler when linking to the dynamic version of the runtime library,
131  * according to "gzh"
132  */
133 // TODO: Define custom macro to govern how libpqxx will be linked to client
134 #if !defined(PQXX_LIBEXPORT) && defined(PQXX_SHARED)
135 #define PQXX_LIBEXPORT __declspec(dllimport)
136 #endif // !PQXX_LIBEXPORT && PQXX_SHARED
137 
138 
139 // Workarounds for Microsoft Visual C++
140 #ifdef _MSC_VER
141 
142 #if _MSC_VER < 1600
143 #error "If you're using Visual C++, you'll need at least the 2010 version."
144 #endif // _MSC_VER < 1600
145 
146 // Automatically link with the appropriate libpq (static or dynamic, debug or
147 // release). The default is to use the release DLL. Define PQXX_PQ_STATIC to
148 // link to a static version of libpq, and _DEBUG to link to a debug version.
149 // The two may be combined.
150 #if defined(PQXX_AUTOLINK)
151 #if defined(PQXX_PQ_STATIC)
152 #ifdef _DEBUG
153 #pragma comment(lib, "libpqd")
154 #else
155 #pragma comment(lib, "libpq")
156 #endif
157 #else
158 #ifdef _DEBUG
159 #pragma comment(lib, "libpqddll")
160 #else
161 #pragma comment(lib, "libpqdll")
162 #endif
163 #endif
164 #endif
165 
166 // If we're not compiling libpqxx itself, automatically link with the correct
167 // libpqxx library. To link with the libpqxx DLL, define PQXX_SHARED; the
168 // default is to link with the static library. This is also the recommended
169 // practice.
170 // Note that the preprocessor macro PQXX_INTERNAL is used to detect whether we
171 // are compiling the libpqxx library itself. When you compile the library
172 // yourself using your own project file, make sure to include this define.
173 #if defined(PQXX_AUTOLINK) && !defined(PQXX_INTERNAL)
174  #ifdef PQXX_SHARED
175  #ifdef _DEBUG
176  #pragma comment(lib, "libpqxxD")
177  #else
178  #pragma comment(lib, "libpqxx")
179  #endif
180  #else // !PQXX_SHARED
181  #ifdef _DEBUG
182  #pragma comment(lib, "libpqxx_staticD")
183  #else
184  #pragma comment(lib, "libpqxx_static")
185  #endif
186  #endif
187 #endif
188 
189 #endif // _MSC_VER
190 #endif // _WIN32
191 
192 #ifndef PQXX_LIBEXPORT
193 #define PQXX_LIBEXPORT
194 #endif
195 
196 #ifndef PQXX_PRIVATE
197 #define PQXX_PRIVATE
198 #endif
199 
200 // Some compilers (well, VC) stumble over some required cases of "typename"
201 #ifndef PQXX_TYPENAME
202 #define PQXX_TYPENAME typename
203 #endif
204 
205 #ifndef PQXX_NOVTABLE
206 #define PQXX_NOVTABLE
207 #endif
208 
209 #endif
210