Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vk4I7-0096Wd-2r for pgsql-hackers@arkaria.postgresql.org; Sun, 25 Jan 2026 17:52:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vk4I5-005K1S-0G for pgsql-hackers@arkaria.postgresql.org; Sun, 25 Jan 2026 17:52:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vk4I4-005K1K-25 for pgsql-hackers@lists.postgresql.org; Sun, 25 Jan 2026 17:52:49 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vk4I2-00000000PKR-01Gv for pgsql-hackers@lists.postgresql.org; Sun, 25 Jan 2026 17:52:48 +0000 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-b87f00ec06aso612010966b.1 for ; Sun, 25 Jan 2026 09:52:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jeltef.nl; s=google; t=1769363560; x=1769968360; darn=lists.postgresql.org; h=in-reply-to:references:from:to:subject:cc:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=DeKrhLd4iTPEQX6atOQFk/YOCuEmi/iucabsN0Cyb+o=; b=HT0gj41AMGvgPk0QvAlgB3nZbP2NQpGnjuZkTb8DHwQDNTpEUyNWQ7LDcxs8ajJWM3 42FduHdEOixZnVWh24K7FLf+5PjHY6GHZVQdDcMoe5izawAngUPCryadU43o4tNr+rRG O6gk8EC+oPRG5HWGcvPYjOR4gucyz5XL+e7EceI12iD0wpDn4Mbs49W+LQD5tB0e48uf URmlZxUwFJRhav1bc4ndxNyQxlnzQr3Nek9TUXr40bcHOJJS0uaqgtsqEhajV1fAvR8l Kzzil+6D+QKCM8JMbmkvrXfQkY+TpnBrgOdK6h+/hnGXZhWDfvdSy84nU0z2MVNDGpG6 XqOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769363560; x=1769968360; h=in-reply-to:references:from:to:subject:cc:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=DeKrhLd4iTPEQX6atOQFk/YOCuEmi/iucabsN0Cyb+o=; b=IJmxQvOq9udQMQNUGxkn3U8yItrMk69SZf7qk+KVQHB+9k0sQOf5JnElZ7RavWnTNo zo+T4SjoBp7TYa1v6Ln9rL8d0bOfJA27RIyQZCoBhmW+L5mKE7rs8fSNZBU907S+nGrg hUOj1ebH/qJ6cjtG/TfuGhtBx4rb5jmzHOnZ9QBPGoh4v6/cL9f8GoIaHuaOT2/r/pkq e2zIMuG25hEOaUbq2tQT+A2uv67ZGrWzt7OxuVfFDduZ/w7o2GEsBVd1NT73hI/U59YW NVzdoxK4AigsxnSdMdvGZLLnAorxM2FQndbQty5NhmDLNHR/FeC3JwTuGCM1ysm9h3O1 tK+A== X-Forwarded-Encrypted: i=1; AJvYcCXTwacX7fLwxAo5O0jZLu9uLM8P0vaiGCPfNLMKnCnwmrMsGRYPRxHBbzebFTUnmuxXpBYOB1Zlc8EgxqMp@lists.postgresql.org X-Gm-Message-State: AOJu0YxT+lSDC9wq7Z9fQ63jVcygWtBFX+c8cbhjCz8dcgH4NsaYN8gU d3M28nftyc5oXM8+KXfEdQEZ6VEtv3IYQ9l4cXjOVMGmzK10Ut2SlM9kpHgJsQBWCtw= X-Gm-Gg: AZuq6aIprSUqJbS7oMwpu2IqifDM9t6yG0kOjfYPMts2Wz8WgzaY2r64n41x2bUa4w4 PO7LKT4cZr963YX5pZ64GAhyKkRJCP2eHsxfJ3VRo+eQBU4rJZAG5vT0Wxj6IMSi4/reyBYuIx8 hVV2J68faH1L4kRwrCChUc4QRwX8c7HqAcH6+4AyHKE92BujvHCzwyAYl9p8Cl2xlBThMH6nxaM UhwWQdz9Ik1ipub5MJ6kusuTWaoT7vvDiKGidWpEGb2U/bvytfu5tfe0+lHdmRYfDVrP7lsvCXJ rsIql9v0fHDHuqS3Kw2HDCPniJpM9KHa5HdTppzzAxZxK0sEeU80sG2AwTSXg7qVrV4HdSekilT pa/UcSVTZOiAwNP6UyjNqJjIzCYS5h60Gf+RCWE2jNJFTCBDuJ1/XCZqX4L0mgantItlsBQvBSm KS2uQaPvimnGW0U32adrTc1jmDPCYh+Ss4ruA= X-Received: by 2002:a17:906:478b:b0:b8a:fc17:56e1 with SMTP id a640c23a62f3a-b8d20d9e3e2mr145694666b.6.1769363559410; Sun, 25 Jan 2026 09:52:39 -0800 (PST) Received: from localhost (145-53-221-196.fixed.kpn.net. [145.53.221.196]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b885b6fe45asm484480866b.35.2026.01.25.09.52.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 25 Jan 2026 09:52:38 -0800 (PST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8; format=Flowed Date: Sun, 25 Jan 2026 18:52:37 +0100 Message-Id: Cc: "Peter Eisentraut" , "PostgreSQL Hackers" , "Thomas Munro" Subject: Re: Make copyObject work in C++ To: "Andres Freund" From: "Jelte Fennema-Nio" X-Mailer: aerc 0.20.1-31-gf6db7c329ce0 References: <4d8b9e53-3f37-43f0-a4aa-5bda9c7961b3@eisentraut.org> <4e82f77b-acad-4356-94f6-8255135fb36b@eisentraut.org> In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun Jan 25, 2026 at 5:50 PM CET, Andres Freund wrote: > I'm pretty sceptical this is the right direction.=20 The only other option I can think of is not supporting C++ extension on MSVC unless they are compiled with C++20 (or later). I don't particularly care about Windows C++ extensions myself, so I personally would be fine with that choice. It seems a bit harsh, though. > We were going for designated > initializers for a reason, namely that we expect more arguments to be add= ed > over time and perhaps eventually also to remove some. And this will just = lead > to that being harder because we have to worry about C++ extensions. Adding new arguments (aka fields) should cause no problems. Assuming we'd add them at the end of the Pg_magic_struct definition. Removing ones seems like even for C you'd need different PG_MODULE_MAGIC_EXT invocations depending on PG_VERSION_NUM. I don't see how using positional args would make that harder. > But I'm also confused as to why it's needed - there's nomixing of designa= ted > and non-designated initializers that I can see? If you use > PG_MODULE_MAGIC_EXT(.name =3D "whatnot"), it evaluates down to > > extern __attribute__((visibility("default"))) const Pg_magic_struct *Pg_m= agic_func(void); const Pg_magic_struct * Pg_magic_func(void) { static const= Pg_magic_struct Pg_magic_data =3D { .len =3D sizeof(Pg_magic_struct), .abi= _fields =3D { 190000 / 100, 100, 32, 64, true, "PostgreSQL", }, .name=3D"wh= atnot"}; return &Pg_magic_data; } extern int no_such_variable; > > And indeed, contra to what you reported upthread, I can't get clang to re= port > a warning about that. I do obviously see warnings about the wrong order = if I > pass the arguments in the wrong order, but that's a lot less problematic.= And > omitted args don't trigger warnings, as you noted. It sounds like I wasn't clear enough what the problem was. The main problem currently is that MSVC C++ fails to compile a cpp file containing PG_MODULE_MAGIC (or PG_MODULE_MAGIC_EXT) unless you use /std:c++= 20. Afaict it would have been possible to do so before 9324c8c580 (aka anything before PG18), but since that commit you need /std:c++20. The fact that we haven't heard anyone complain so far, might be an indication that not many people (or maybe anyone) is using C++ extensions on Windows. The only way to make PG_MODULE_MAGIC work on MSVC pre-C++20 is to partially revert 9324c8c580, and use positional arguments in the definition of PG_MODULE_MAGIC_DATA again. Like I've done in v7-0001. For C extensions v7-0001 has no downsides. However, after applying v7-0001, C++ extensions that use PG_MODULE_MAGIC_EXT with designated parameters will get the following warning on at least clang 18 on my machine: meson setup --prefix ~/.pgenv/pgsql-master --debug build --reconfigure -Dc_= args=3D'-fno-omit-frame-pointer' -Dcassert=3Dtrue meson test -C build --suite setup --suite test_cplusplusext [2202/2268] Compiling C++ object src/test/modules/test_cplusplusext/test_cp= lusplusext.so.p/test_cplusplusext.cpp.o ../src/test/modules/test_cplusplusext/test_cplusplusext.cpp:23:21: warning:= mixture of designated and non-designated initializers in the same initiali= zer list is a C99 extension [-Wc99-designator] 23 | PG_MODULE_MAGIC_EXT(.name=3D"test_cplusplusext",.version=3D "1.2"); | ^~~~~~~~~~~~~~~~~~~~~~~~~ ../src/include/fmgr.h:548:24: note: expanded from macro 'PG_MODULE_MAGIC_EX= T' 548 | PG_MODULE_MAGIC_DATA(__VA_ARGS__); \ | ^~~~~~~~~~~ ../src/include/fmgr.h:509:2: note: expanded from macro 'PG_MODULE_MAGIC_DAT= A' 509 | __VA_ARGS__ \ | ^~~~~~~~~~~ ../src/test/modules/test_cplusplusext/test_cplusplusext.cpp:23:1: note: fir= st non-designated initializer is here 23 | PG_MODULE_MAGIC_EXT(.name=3D"test_cplusplusext",.version=3D "1.2"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../src/include/fmgr.h:548:3: note: expanded from macro 'PG_MODULE_MAGIC_EXT= ' 548 | PG_MODULE_MAGIC_DATA(__VA_ARGS__); \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../src/include/fmgr.h:507:2: note: expanded from macro 'PG_MODULE_MAGIC_DAT= A' 507 | sizeof(Pg_magic_struct), \ | ^~~~~~~~~~~~~~~~~~~~~~~ Note that you need to use meson test, not meson install, otherwise test_cplusplusext.cpp won't get compiled. So to be clear, yes right now there's no mixing of designated and non-designated initializers. But after applying v7-0001 there would be when you use something like this: PG_MODULE_MAGIC_EXT(.name=3D"test_cplusplusext",.version=3D "1.2"); And while the C standard allows mixing designated and non-designated initializerss, the C++ standard (even C++20) does not.