]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Make fixed-length list building macros work in C++
authorPeter Eisentraut <peter@eisentraut.org>
Thu, 26 Mar 2026 07:40:18 +0000 (08:40 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Thu, 26 Mar 2026 07:53:13 +0000 (08:53 +0100)
Compound literals, as used in pg_list.h for list_makeN(), are not a
C++ feature.  MSVC doesn't accept these.  (GCC and Clang accept them,
but they would warn in -pedantic mode.)  Replace with equivalent
inline functions.  (These are the only instances of compound literals
used in PostgreSQL header files.)

Author: Jelte Fennema-Nio <postgres@jeltef.nl>
Discussion: https://www.postgresql.org/message-id/flat/CAGECzQR21OnnKiZO_1rLWO0-16kg1JBxnVq-wymYW0-_1cUNtg%40mail.gmail.com

src/include/nodes/pg_list.h

index ae80975548f19a9a83cd600c422d26b03ad241c6..e93bcbf2698d6ffaf11569fa1f3bad784048adef 100644 (file)
@@ -204,10 +204,42 @@ list_length(const List *l)
 /*
  * Convenience macros for building fixed-length lists
  */
-#define list_make_ptr_cell(v)  ((ListCell) {.ptr_value = (v)})
-#define list_make_int_cell(v)  ((ListCell) {.int_value = (v)})
-#define list_make_oid_cell(v)  ((ListCell) {.oid_value = (v)})
-#define list_make_xid_cell(v)  ((ListCell) {.xid_value = (v)})
+
+static inline ListCell
+list_make_ptr_cell(void *v)
+{
+       ListCell        c;
+
+       c.ptr_value = v;
+       return c;
+}
+
+static inline ListCell
+list_make_int_cell(int v)
+{
+       ListCell        c;
+
+       c.int_value = v;
+       return c;
+}
+
+static inline ListCell
+list_make_oid_cell(Oid v)
+{
+       ListCell        c;
+
+       c.oid_value = v;
+       return c;
+}
+
+static inline ListCell
+list_make_xid_cell(TransactionId v)
+{
+       ListCell        c;
+
+       c.xid_value = v;
+       return c;
+}
 
 #define list_make1(x1) \
        list_make1_impl(T_List, list_make_ptr_cell(x1))