Skip to content

Commit baf7c93

Browse files
committed
Define unconstify() and unvolatize() for C++.
These two macros wouldn't work if used in an inline function definition in a header seen by g++, because __builtin_types_compatible_p is only available in C. Redirect to standard C++ const_cast (which also adds/removes volatile despite its name). Per cpluspluscheck failure in a development branch. Suggested-by: Peter Eisentraut <peter@eisentraut.org> Discussion: https://postgr.es/m/CA%2BhUKGK3OXFjkOyZiw-DgL2bUqk9by1uGuCnViJX786W%2BfyDSw%40mail.gmail.com
1 parent 0a5c46a commit baf7c93

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/include/c.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,10 @@ typedef union PGAlignedXLogBlock
12451245
* Note that this only works in function scope, not for global variables (it'd
12461246
* be nice, but not trivial, to improve that).
12471247
*/
1248-
#if defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
1248+
#if defined(__cplusplus)
1249+
#define unconstify(underlying_type, expr) const_cast<underlying_type>(expr)
1250+
#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
1251+
#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
12491252
#define unconstify(underlying_type, expr) \
12501253
(StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
12511254
"wrong cast"), \

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy