Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

+4-1
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)