Hi Branden,

When compiling Groff with GCC/G++ 15.0, I run into this compiler error:

      CXX      src/roff/troff/div.o
    In file included from src/roff/troff/div.cpp:29:
    src/roff/troff/hvunits.h: In member function ‘units vunits::to_units()’:
    src/roff/troff/hvunits.h:91:7: error: ‘ckd_mul’ was not declared in this 
scope
       91 |   if (ckd_mul(&r, n, vresolution))
          |       ^~~~~~~
    src/roff/troff/hvunits.h: In function ‘vunits operator+(const vunits&, 
const vunits&)’:
    src/roff/troff/hvunits.h:105:7: error: ‘ckd_add’ was not declared in this 
scope
      105 |   if (ckd_add(&r.n, r.n, y.n))

This is because in /usr/include/c++/15/stdckdint.h

    #if __cplusplus > 202302L
    /* Template wizardry to define ckd_*.  */
    #endif

The immediate fix that comes to mind is using 'g++ -std=gnu23', but
there are 2 issues with this:

    1. gnulib/m4/std-gnu23.m4 has no code for C++ versions, because no
    one interested in C++ has contributed it to Autoconf yet.
    2. Bruno told me that the C++ standards are not compatible with each
    other, so there would probably be more issues caused by the change
    [1].

I have committed the two attached patches to Gnulib. If the system has
<stdbit.h> and C++ is in use, we just generate <stdbit.h> and include
it. That way these macros will be defined.

My assumption here is that if a system is modern enough to have
<stdbit.h> it's C++ compiler supports __builtin_*_overflow. Since I
assume lib/intprops.h is not compatible with C++. This should be true
for GCC and Clang. For MSVC, I will probably have to add C++
templates...

[1] https://lists.gnu.org/archive/html/bug-gnulib/2025-04/msg00176.html

>From 5948807b3e200214799d323d9784e74fa5f72e23 Mon Sep 17 00:00:00 2001
Message-ID: <5948807b3e200214799d323d9784e74fa5f72e23.1747715373.git.collin.fu...@gmail.com>
From: Collin Funk <collin.fu...@gmail.com>
Date: Mon, 19 May 2025 21:23:56 -0700
Subject: [PATCH 1/2] stdckdint-h C++ tests: Verify the ckd_* functions can be
 invoked.

* tests/test-stdckdint-h-c++.cc (main): Invoke ckd_add, ckd_sub, and
ckd_mul.
---
 ChangeLog                     | 6 ++++++
 tests/test-stdckdint-h-c++.cc | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 75792d4fe2..2351f847ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-05-19  Collin Funk  <collin.fu...@gmail.com>
+
+	stdckdint-h C++ tests: Verify the ckd_* functions can be invoked.
+	* tests/test-stdckdint-h-c++.cc (main): Invoke ckd_add, ckd_sub, and
+	ckd_mul.
+
 2025-05-18  Paul Eggert  <egg...@cs.ucla.edu>
 
 	tests: simplify test_exit_status decl
diff --git a/tests/test-stdckdint-h-c++.cc b/tests/test-stdckdint-h-c++.cc
index 00680385cf..071d7be740 100644
--- a/tests/test-stdckdint-h-c++.cc
+++ b/tests/test-stdckdint-h-c++.cc
@@ -25,4 +25,10 @@
 int
 main ()
 {
+  /* We only check that the macros can be invoked here.  The actual tests are
+     performed by the C program.  */
+  int r;
+  int a = 1;
+  int b = 1;
+  return !!(ckd_add (&r, a, b) || ckd_sub (&r, a, b) || ckd_mul (&r, a, b));
 }
-- 
2.49.0

>From 7ee6e40b6730c87e5c1323bb5c2564bcb6eff9e4 Mon Sep 17 00:00:00 2001
Message-ID: <7ee6e40b6730c87e5c1323bb5c2564bcb6eff9e4.1747715373.git.collin.fu...@gmail.com>
In-Reply-To: <5948807b3e200214799d323d9784e74fa5f72e23.1747715373.git.collin.fu...@gmail.com>
References: <5948807b3e200214799d323d9784e74fa5f72e23.1747715373.git.collin.fu...@gmail.com>
From: Collin Funk <collin.fu...@gmail.com>
Date: Mon, 19 May 2025 21:29:03 -0700
Subject: [PATCH 2/2] stdckdint-h: Work around missing declarations with g++
 15.0.

* modules/stdckdint-h (configure.ac): Generate the header if the system
has one and C++ is being used.
---
 ChangeLog           | 4 ++++
 modules/stdckdint-h | 6 +++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 2351f847ef..b85c7c6e6e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2025-05-19  Collin Funk  <collin.fu...@gmail.com>
 
+	stdckdint-h: Work around missing declarations with g++ 15.0.
+	* modules/stdckdint-h (configure.ac): Generate the header if the system
+	has one and C++ is being used.
+
 	stdckdint-h C++ tests: Verify the ckd_* functions can be invoked.
 	* tests/test-stdckdint-h-c++.cc (main): Invoke ckd_add, ckd_sub, and
 	ckd_mul.
diff --git a/modules/stdckdint-h b/modules/stdckdint-h
index 24e26cfb69..ff777d8d62 100644
--- a/modules/stdckdint-h
+++ b/modules/stdckdint-h
@@ -12,7 +12,11 @@ bool
 configure.ac:
 AC_CHECK_HEADERS_ONCE([stdckdint.h])
 if test $ac_cv_header_stdckdint_h = yes; then
-  GL_GENERATE_STDCKDINT_H=false
+  if test -n "$CXX" && test "$CXX" != no; then
+    GL_GENERATE_STDCKDINT_H=true
+  else
+    GL_GENERATE_STDCKDINT_H=false
+  fi
 else
   GL_GENERATE_STDCKDINT_H=true
 fi
-- 
2.49.0

Reply via email to