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 1vSWgN-00H3eA-0s for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Dec 2025 08:33:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vSWgK-00FfH7-1r for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Dec 2025 08:33:20 +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 1vSWgK-00FfGs-0t for pgsql-hackers@lists.postgresql.org; Mon, 08 Dec 2025 08:33:20 +0000 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vSWgI-003oWe-0y for pgsql-hackers@lists.postgresql.org; Mon, 08 Dec 2025 08:33:20 +0000 Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-7c701097a75so2574252a34.3 for ; Mon, 08 Dec 2025 00:33:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765182796; x=1765787596; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=XbM//nNHGTWeg2lim1l4Y9BYve3LRusyKJnk4TGEOOk=; b=jZ+9K+XEDARBky3kYkdgUB3hzzFi4hRRpU+OMPrV+FJlIkurVtzQFmZZKgnUPBqBwp A0K+otLZGtTscOUfrTQH4QqaNWeX5xkoyznDv3Zzd3BOGtlpZmNn1TRldmwe9MzEeGSw DA2ug3ba6O+R9cJRBnTE/q/5BSN57e72OCpUWt6iB04xmncdtqxohVycQT6jnWNL8R2a 9b4WEO3vwuyCZCEcu/0c3ctmLK/N6YTm6AY9rWfr+nur3YF2xtF1mHGApWEIIvZocN5x kR5UXQNX1zO9ct+UEKE3lpAtVyvuO/aCp2Kew6+1WhBZbg9Cs+DRfyHaULNxfrFQDr+y ngZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765182796; x=1765787596; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XbM//nNHGTWeg2lim1l4Y9BYve3LRusyKJnk4TGEOOk=; b=Qka3FVCEr3tKvoUVi/6ZdHSeiwdlHlFUZNPLvdqHTCbBQ0iSL29lnDTPrp/uxr3ffN g2P8O1uZReDNlZyyvTNMadNqpoDEiSt6wjqxiDOZpwvtNiwhF3svYi2HyWiari2llfkl WhgYp0kHsYryg8JefaMbeNT7vXtMycHPjDI5Bt9w0+PQzJi/ugOtHvcwiIFt/5DrwljN +zgMw4ruXRij+qQWur5SR66uEYD9geCWnotdnE+vcl7fNaSu4Ig9HDH5XLCfD+Q3DzHR 82Acp8ViZzz3FGPal8o6JfYariHds/xMqVT4uAFprJ3ZkWlkT8Ye1Ku96GckopnDlVSU 9WwA== X-Forwarded-Encrypted: i=1; AJvYcCWZNLGVLuNPmt8xxPlH1bMnFW9a44/rylGW4l8zmhVzRFMjHMCGGgb2vMynV0j5VsXYWXGSUoyub6Px3L+u@lists.postgresql.org X-Gm-Message-State: AOJu0YyxfQturypRtLXarJ/CIurjkal+IRrNKYLkRSDDrfVr8BCpzYn6 GyXqjmQ0WbSxEW513bRQuzZ3KN8EwD4hKcwzwqOXSD67iwZvPzdtrHXd X-Gm-Gg: ASbGnctsksIjKTR8OdE+ZqgGexa8EuR5xv73TvyWVEmpriu0cG/Y44G0aNCfiPGyJxa zdde0Wlc+/CfdXWoSl0yuFReuSerWHJVAnH2d2dsnIdCGgyaRf3Q5p/bGkRtiEFL+d1UZOb3+O4 yo+JjQtiU/WVlzRuhSuD63CYTqfla6hdvbrOgpEAgINq/wjgnBlBcgKKlyJCtsrSQ0E1zKmqaCB jyDMqA1Q4E3Ap3w63YDhHrEq2DF93JkbeL+pdMnpYlctKcAJ9khzdpmkSSzlOycr4pNOeTZxEjH Gw69FS1mU5fz51kC2PS1RMExKZkyTfAbegh8K1aF6n0CzZ4EGcjThW31z7bRBtJ/cdH6PLWmkbY orbnM2A+MUooaiCtl5NFLOyR+nQ8uH7e5BR5MfSlzZEKEZ3jqUij0ofAau0/WKwzXFWscuGijHs R24sT8kZ5sRNJ4adR9Hh9vdqQHfB0X1pXAsFVFYoMWVtN8gz+g X-Google-Smtp-Source: AGHT+IFBr4ac6JvG32N8OauY/cwsp8b1M7DaMxPpGDfrljmJPbqr3TGifimKVz69tb1lAVhYziWZAw== X-Received: by 2002:a05:6830:4492:b0:7c7:e29:70ca with SMTP id 46e09a7af769-7c9707cb66bmr3747351a34.22.1765182795824; Mon, 08 Dec 2025 00:33:15 -0800 (PST) Received: from [192.168.2.32] (p5df36877.dip0.t-ipconnect.de. [93.243.104.119]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7c95ac84f1dsm9503863a34.19.2025.12.08.00.33.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Dec 2025 00:33:15 -0800 (PST) Message-ID: Date: Mon, 8 Dec 2025 09:33:10 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Make copyObject work in C++ To: Peter Eisentraut , Jelte Fennema-Nio , PostgreSQL Hackers , Thomas Munro References: <1bec56e5-aef9-4d3b-b4ee-723c6575a44e@eisentraut.org> Content-Language: en-US From: David Geier In-Reply-To: <1bec56e5-aef9-4d3b-b4ee-723c6575a44e@eisentraut.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 08.12.2025 08:57, Peter Eisentraut wrote: > On 05.12.25 15:46, Jelte Fennema-Nio wrote: >> Calling copyObject fails in C++ with an error like in most setups: >> >> error: use of undeclared identifier 'typeof'; did you mean 'typeid' >> >> This is due to the C compiler supporting used to compile postgres >> supporting typeof, but that function actually not being present in the >> C++ compiler. This fixes that by using decltype instead of typeof when >> including the header in C++. >> >> Realized because of Thomas' not about how much of our headers should >> work in C++, and remembering I hit this specific problem myself. >> >> Another approach would be to force the value of HAVE_TYPEOF to 0 if >> __cplusplus. > > In the long run, I would like to change copyObject() to use > typeof_unqual instead, because that handles qualifiers more correctly. > (Currently, copyObject() of a const-qualified pointer results in a > const-qualified pointer, which is nonsensical because the reason you > made the copy is that you can modify it.)  See attached patch for an > example.  Does C++ have something that is semantically similar to that? Since C++11 there's std::remove_const which can be used as std::remove_const::type. I'm not aware of anything pre C++11, except for rolling your own variant of std::remove_const via template specialization. -- David Geier