libpqxx
The C++ client library for PostgreSQL
header-pre.hxx
1 /* Compiler settings for compiling libpqxx headers, and workarounds for all.
2  *
3  * Include this before including any other libpqxx headers from within libpqxx.
4  * And to balance it out, also include header-post.hxx at the end of the batch
5  * of headers.
6  *
7  * The public libpqxx headers (e.g. `<pqxx/connection>`) include this already;
8  * there's no need to do this from within an application.
9  *
10  * Include this file at the highest aggregation level possible to avoid nesting
11  * and to keep things simple.
12  *
13  * Copyright (c) 2000-2025, Jeroen T. Vermeulen.
14  *
15  * See COPYING for copyright license. If you did not receive a file called
16  * COPYING with this source code, please notify the distributor of this
17  * mistake, or contact the author.
18  */
19 
20 #if __has_include(<version>)
21 # include <version>
22 #endif
23 
24 // NO GUARD HERE! This part should be included every time this file is.
25 #if defined(_MSC_VER)
26 
27 // Save compiler's warning state, and set warning level 4 for maximum
28 // sensitivity to warnings.
29 # pragma warning(push, 4)
30 
31 // Visual C++ generates some entirely unreasonable warnings. Disable them.
32 // Copy constructor could not be generated.
33 # pragma warning(disable : 4511)
34 // Assignment operator could not be generated.
35 # pragma warning(disable : 4512)
36 // Can't expose outside classes without exporting them. Except the MSVC docs
37 // say please ignore the warning if it's a standard library class.
38 # pragma warning(disable : 4251)
39 // Can't derive library classes from outside classes without exporting them.
40 // Except the MSVC docs say please ignore the warning if the parent class is
41 // in the standard library.
42 # pragma warning(disable : 4275)
43 // Can't inherit from non-exported class.
44 # pragma warning(disable : 4275)
45 
46 #endif // _MSC_VER
47 
48 
49 #if defined(PQXX_HEADER_PRE)
50 # error "Avoid nesting #include of pqxx/internal/header-pre.hxx."
51 #endif
52 
53 #define PQXX_HEADER_PRE
54 
55 
56 // Workarounds & definitions that need to be included even in library's headers
57 #include "pqxx/config-public-compiler.h"
58 
59 // MSVC has a nonstandard definition of __cplusplus.
60 #if defined(_MSC_VER)
61 # define PQXX_CPLUSPLUS _MSVC_LANG
62 #else
63 # define PQXX_CPLUSPLUS __cplusplus
64 #endif
65 
66 // C++20: No longer needed.
67 // Enable ISO-646 alternative operator representations: "and" instead of "&&"
68 // etc. on older compilers. C++17 deprecates this header; C++20 removes it.
69 #if defined(_MSC_VER) && __has_include(<ciso646>) && PQXX_CPLUSPLUS <= 201703L
70 // MSVC. This compiler is being difficult: it requires us to include this
71 // header in C++17, but will also complain that it's deprecated.
72 # include <ciso646>
73 #endif
74 
75 #if defined(PQXX_HAVE_GCC_PURE)
76 # define PQXX_PURE __attribute__((pure))
78 #else
79 # define PQXX_PURE /* pure */
80 #endif
81 
82 
83 #if defined(__GNUC__)
84 # define PQXX_COLD __attribute__((cold))
86 #else
87 # define PQXX_COLD /* cold */
88 #endif
89 
90 
91 // Workarounds for Windows
92 #ifdef _WIN32
93 
94 /* For now, export DLL symbols if _DLL is defined. This is done automatically
95  * by the compiler when linking to the dynamic version of the runtime library,
96  * according to "gzh"
97  */
98 # if defined(PQXX_SHARED) && !defined(PQXX_LIBEXPORT)
99 # define PQXX_LIBEXPORT __declspec(dllimport)
100 # endif // PQXX_SHARED && !PQXX_LIBEXPORT
101 
102 
103 // Workarounds for Microsoft Visual C++
104 # ifdef _MSC_VER
105 
106 // Suppress vtables on abstract classes.
107 # define PQXX_NOVTABLE __declspec(novtable)
108 
109 // Automatically link with the appropriate libpq (static or dynamic, debug or
110 // release). The default is to use the release DLL. Define PQXX_PQ_STATIC to
111 // link to a static version of libpq, and _DEBUG to link to a debug version.
112 // The two may be combined.
113 # if defined(PQXX_AUTOLINK)
114 # if defined(PQXX_PQ_STATIC)
115 # ifdef _DEBUG
116 # pragma comment(lib, "libpqd")
117 # else
118 # pragma comment(lib, "libpq")
119 # endif
120 # else
121 # ifdef _DEBUG
122 # pragma comment(lib, "libpqddll")
123 # else
124 # pragma comment(lib, "libpqdll")
125 # endif
126 # endif
127 # endif
128 
129 // If we're not compiling libpqxx itself, automatically link with the
130 // appropriate libpqxx library. To link with the libpqxx DLL, define
131 // PQXX_SHARED; the default is to link with the static library. A static link
132 // is the recommended practice.
133 //
134 // The preprocessor macro PQXX_INTERNAL is used to detect whether we
135 // are compiling the libpqxx library itself. When you compile the library
136 // yourself using your own project file, make sure to include this macro.
137 # if defined(PQXX_AUTOLINK) && !defined(PQXX_INTERNAL)
138 # ifdef PQXX_SHARED
139 # ifdef _DEBUG
140 # pragma comment(lib, "libpqxxD")
141 # else
142 # pragma comment(lib, "libpqxx")
143 # endif
144 # else // !PQXX_SHARED
145 # ifdef _DEBUG
146 # pragma comment(lib, "libpqxx_staticD")
147 # else
148 # pragma comment(lib, "libpqxx_static")
149 # endif
150 # endif
151 # endif
152 
153 # endif // _MSC_VER
154 
155 #elif defined(PQXX_HAVE_GCC_VISIBILITY) // !_WIN32
156 
157 # define PQXX_LIBEXPORT __attribute__((visibility("default")))
158 # define PQXX_PRIVATE __attribute__((visibility("hidden")))
159 
160 #endif // PQXX_HAVE_GCC_VISIBILITY
161 
162 
163 #ifndef PQXX_LIBEXPORT
164 # define PQXX_LIBEXPORT /* libexport */
165 #endif
166 
167 #ifndef PQXX_PRIVATE
168 # define PQXX_PRIVATE /* private */
169 #endif
170 
171 #ifndef PQXX_NOVTABLE
172 # define PQXX_NOVTABLE /* novtable */
173 #endif
174 
175 // C++20: Assume support.
176 #if defined(PQXX_HAVE_LIKELY)
177 # define PQXX_LIKELY [[likely]]
178 # define PQXX_UNLIKELY [[unlikely]]
179 #else
180 # define PQXX_LIKELY /* [[likely]] */
181 # define PQXX_UNLIKELY /* [[unlikely]] */
182 #endif
183 
184 
185 // C++23: Assume support.
186 #if defined(PQXX_HAVE_ASSUME)
187 # define PQXX_ASSUME(condition) [[assume(condition)]]
188 #else
189 # define PQXX_ASSUME(condition) while (false)
190 #endif