bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* Fix error in C++ mode on glibc systems
@ 2023-02-09 12:21 Bruno Haible
  0 siblings, 0 replies; only message in thread
From: Bruno Haible @ 2023-02-09 12:21 UTC (permalink / raw)
  To: bug-gnulib

When compiling a Gnulib testdir with clang15 with -std=gnu2x option,
on a CentOS 8 Stream system, I see this compilation error:

In file included from ../../gltests/test-nullptr-c++.cc:30:
In file included from ../../gltests/macros.h:22:
../gllib/stdlib.h:756:1: error: exception specification in declaration does not match previous declaration
_GL_FUNCDECL_RPL (free, void, (void *ptr) throw ());
^
../gllib/wchar.h:238:23: note: expanded from macro '_GL_FUNCDECL_RPL'
  _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
                      ^
<scratch space>:194:1: note: expanded from here
rpl_free
^
../gllib/wchar.h:698:19: note: previous declaration is here
_GL_EXTERN_C void rpl_free (void *);
                  ^
1 error generated.

The cause is that on 2022-04-28 we added the 'throw ()' annotation to
the rpl_free declaration in stdlib.h.
https://lists.gnu.org/archive/html/bug-gnulib/2022-04/msg00072.html
But we have similar declarations also in malloc.h, string.h, wchar.h, and
they all need to be consistent.

This patch fixes it.


2023-02-09  Bruno Haible  <bruno@clisp.org>

	Fix error in C++ mode on glibc systems (regression 2022-04-28).
	* lib/malloc.in.h (rpl_free): Add exception specification like
	stdlib.in.h does.
	* lib/string.in.h (rpl_free): Likewise.
	* lib/wchar.in.h (rpl_free): Likewise.

diff --git a/lib/malloc.in.h b/lib/malloc.in.h
index 4921f6e994..2fcbe23535 100644
--- a/lib/malloc.in.h
+++ b/lib/malloc.in.h
@@ -65,7 +65,11 @@
 # if (@REPLACE_FREE@ && !defined free \
       && !(defined __cplusplus && defined GNULIB_NAMESPACE))
 /* We can't do '#define free rpl_free' here.  */
+#  if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
+_GL_EXTERN_C void rpl_free (void *) throw ();
+#  else
 _GL_EXTERN_C void rpl_free (void *);
+#  endif
 #  undef _GL_ATTRIBUTE_DEALLOC_FREE
 #  define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (rpl_free, 1)
 # else
diff --git a/lib/string.in.h b/lib/string.in.h
index aa08821392..b6bf432e1f 100644
--- a/lib/string.in.h
+++ b/lib/string.in.h
@@ -126,7 +126,11 @@
 # if (@REPLACE_FREE@ && !defined free \
       && !(defined __cplusplus && defined GNULIB_NAMESPACE))
 /* We can't do '#define free rpl_free' here.  */
+#  if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
+_GL_EXTERN_C void rpl_free (void *) throw ();
+#  else
 _GL_EXTERN_C void rpl_free (void *);
+#  endif
 #  undef _GL_ATTRIBUTE_DEALLOC_FREE
 #  define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (rpl_free, 1)
 # else
diff --git a/lib/wchar.in.h b/lib/wchar.in.h
index bbca92797d..2beddd780f 100644
--- a/lib/wchar.in.h
+++ b/lib/wchar.in.h
@@ -188,7 +188,11 @@ typedef int rpl_mbstate_t;
 # if (@REPLACE_FREE@ && !defined free \
       && !(defined __cplusplus && defined GNULIB_NAMESPACE))
 /* We can't do '#define free rpl_free' here.  */
+#  if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2)
+_GL_EXTERN_C void rpl_free (void *) throw ();
+#  else
 _GL_EXTERN_C void rpl_free (void *);
+#  endif
 #  undef _GL_ATTRIBUTE_DEALLOC_FREE
 #  define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (rpl_free, 1)
 # else





^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-09 12:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-09 12:21 Fix error in C++ mode on glibc systems Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).