On Fri, Jul 4, 2025 at 10:11 PM Tom Lane <t...@sss.pgh.pa.us> wrote:
>
> Andres Freund <and...@anarazel.de> writes:

> >> +/* restore so that extensions can include the C++ APIs */
> >> +#undef U_SHOW_CPLUSPLUS_API
>
> > Does the #undef U_SHOW_CPLUSPLUS_API thing actually work, given that ucol.h
> > presumably won't be included again due to #ifdef protection?
>
> Good point.  If a .cpp file wants access to the C++ APIs, it'd have
> to include <unicode/ucol.h> before not after including pg_locale.h.
> That should work AFAICS, but this #undef doesn't help.

I see that now. If extensions follow the practice of including system
headers before Postgres headers, it should be fine. I've attached v2
which removes the useless #undef and drafts an explanatory commit
message.

--
John Naylor
Amazon Web Services
From 23fef0965cc2c75b32e531ac670cf31c0b4bd610 Mon Sep 17 00:00:00 2001
From: John Naylor <john.nay...@postgresql.org>
Date: Mon, 7 Jul 2025 12:28:05 +0700
Subject: [PATCH v2] Hide ICU C++ APIs from pg_locale.h

The cpluspluscheck script wraps our headers in `extern "C"`. This
disables name mangling, which is necessary for the C++ templates in
system ICU headers. This breaks cpluspluscheck when configured with
ICU (the default). CI worked around this by disabling ICU, but let's
make it work so others can run the script.

We can specify we only want the C APIs by defining U_SHOW_CPLUSPLUS_API
to be 0 in pg_locale.h. Extensions that want the C++ APIs can include
ICU headers separately before including PostgreSQL headers.

ICU documentation:
https://github.com/unicode-org/icu/blob/main/docs/processes/release/tasks/healthy-code.md#test-icu4c-headers

Suggested-by: Andres Freund <and...@anarazel.de>
Reviewed-by: Peter Eisentraut <pe...@eisentraut.org>
Reviewed-by: Tom Lane <t...@sss.pgh.pa.us>
Discussion: https://postgr.es/m/20220323002024.f2g6tivduzrktgfa%40alap3.anarazel.de
Discussion: https://postgr.es/m/CANWCAZbgiaz1_0-F4SD%2B%3D-e9onwAnQdBGJbhg94EqUu4Gb7WyA%40mail.gmail.com
---
 .cirrus.tasks.yml             | 3 ---
 src/include/utils/pg_locale.h | 3 +++
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
index 92057006c93..1a366975d82 100644
--- a/.cirrus.tasks.yml
+++ b/.cirrus.tasks.yml
@@ -938,14 +938,11 @@ task:
   # - Don't use ccache, the files are uncacheable, polluting ccache's
   #   cache
   # - Use -fmax-errors, as particularly cpluspluscheck can be very verbose
-  # - XXX have to disable ICU to avoid errors:
-  #   https://postgr.es/m/20220323002024.f2g6tivduzrktgfa%40alap3.anarazel.de
   ###
   always:
     headers_headerscheck_script: |
       time ./configure \
         ${LINUX_CONFIGURE_FEATURES} \
-        --without-icu \
         --quiet \
         CC="gcc" CXX"=g++" CLANG="clang-16"
       make -s -j${BUILD_JOBS} clean
diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h
index 44ff60a25b4..1cd7c76a0a7 100644
--- a/src/include/utils/pg_locale.h
+++ b/src/include/utils/pg_locale.h
@@ -15,6 +15,9 @@
 #include "mb/pg_wchar.h"
 
 #ifdef USE_ICU
+/* only include the C APIs, to avoid errors in cpluspluscheck */
+#undef U_SHOW_CPLUSPLUS_API
+#define U_SHOW_CPLUSPLUS_API 0
 #include <unicode/ucol.h>
 #endif
 
-- 
2.50.0

Reply via email to