changeset 12984:e9d0fdd4293b

Fix compilation error with glibc >= 2.10 and g++ >= 4.4.
author Bruno Haible <bruno@clisp.org>
date Sat, 13 Mar 2010 12:06:23 +0100
parents 39ddc4b73387
children 323f5ed9a51c
files ChangeLog build-aux/c++defs.h build-aux/warn-on-use.h lib/string.in.h
diffstat 4 files changed, 98 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Mar 12 14:44:11 2010 +0100
+++ b/ChangeLog	Sat Mar 13 12:06:23 2010 +0100
@@ -1,3 +1,13 @@
+2010-03-13  Bruno Haible  <bruno@clisp.org>
+
+	Fix compilation error with glibc >= 2.10 and g++ >= 4.4.
+	* build-aux/warn-on-use.h (_GL_WARN_ON_USE_CXX): New macro.
+	* build-aux/c++defs.h (_GL_CXXALIASWARN1): New macro.
+	* lib/string.in.h (memchr, memrchr, rawmemchr, strchrnul, strpbrk,
+	strstr, strcasestr): Use _GL_CXXALIASWARN1 instead of _GL_CXXALIASWARN
+	when appropriate.
+	Reported by Jim Meyering.
+
 2010-03-12  Simon Josefsson  <simon@josefsson.org>
 
 	* gnulib-tool (func_import): Explain origin of code.
--- a/build-aux/c++defs.h	Fri Mar 12 14:44:11 2010 +0100
+++ b/build-aux/c++defs.h	Sat Mar 13 12:06:23 2010 +0100
@@ -196,13 +196,14 @@
 
 /* _GL_CXXALIASWARN (func);
    causes a warning to be emitted when ::func is used but not when
-   GNULIB_NAMESPACE::func is used.  */
+   GNULIB_NAMESPACE::func is used.  func must be defined without overloaded
+   variants.  */
 #if defined __cplusplus && defined GNULIB_NAMESPACE
 # define _GL_CXXALIASWARN(func) \
-   _GL_CXXALIASWARN1 (func, GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN1(func,namespace) \
-   _GL_CXXALIASWARN2 (func, namespace)
-# define _GL_CXXALIASWARN2(func,namespace) \
+   _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN_1(func,namespace) \
+   _GL_CXXALIASWARN_2 (func, namespace)
+# define _GL_CXXALIASWARN_2(func,namespace) \
    _GL_WARN_ON_USE (func, \
                     "The symbol ::" #func " refers to the system function. " \
                     "Use " #namespace "::" #func " instead.")
@@ -211,4 +212,22 @@
     _GL_EXTERN_C int _gl_cxxalias_dummy
 #endif
 
+/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
+   causes a warning to be emitted when the given overloaded variant of ::func
+   is used but not when GNULIB_NAMESPACE::func is used.  */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+#  _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
+                        GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
+   _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+   _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
+                        "The symbol ::" #func " refers to the system function. " \
+                        "Use " #namespace "::" #func " instead.")
+#else
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+    _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
 #endif /* _GL_CXXDEFS_H */
--- a/build-aux/warn-on-use.h	Fri Mar 12 14:44:11 2010 +0100
+++ b/build-aux/warn-on-use.h	Sat Mar 13 12:06:23 2010 +0100
@@ -14,7 +14,7 @@
    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-/* _GL_WARN_ON_USE(function, "literal string") issues a declaration
+/* _GL_WARN_ON_USE (function, "literal string") issues a declaration
    for FUNCTION which will then trigger a compiler warning containing
    the text of "literal string" anywhere that function is called, if
    supported by the compiler.  If the compiler does not support this
@@ -73,3 +73,20 @@
 extern int _gl_warn_on_use
 # endif
 #endif
+
+/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
+   is like _GL_WARN_ON_USE (function, "string"), except that the function is
+   declared with the given prototype, consisting of return type, parameters,
+   and attributes.
+   This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
+   not work in this case.  */
+#ifndef _GL_WARN_ON_USE_CXX
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+#  define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes \
+     __attribute__ ((__warning__ (msg)))
+# else /* Unsupported.  */
+#  define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern int _gl_warn_on_use
+# endif
+#endif
--- a/lib/string.in.h	Fri Mar 12 14:44:11 2010 +0100
+++ b/lib/string.in.h	Sat Mar 13 12:06:23 2010 +0100
@@ -73,7 +73,14 @@
                         void *, (void const *__s, int __c, size_t __n),
                         void const *, (void const *__s, int __c, size_t __n));
 # endif
+# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
+     && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+_GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n));
+_GL_CXXALIASWARN1 (memchr, void const *,
+                   (void const *__s, int __c, size_t __n));
+# else
 _GL_CXXALIASWARN (memchr);
+# endif
 #elif defined GNULIB_POSIXCHECK
 # undef memchr
 /* Assume memchr is always declared.  */
@@ -149,7 +156,13 @@
 _GL_CXXALIAS_SYS_CAST2 (memrchr,
                         void *, (void const *, int, size_t),
                         void const *, (void const *, int, size_t));
+# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
+     && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+_GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t));
+_GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t));
+# else
 _GL_CXXALIASWARN (memrchr);
+# endif
 #elif defined GNULIB_POSIXCHECK
 # undef memrchr
 # if HAVE_RAW_DECL_MEMRCHR
@@ -173,7 +186,13 @@
 _GL_CXXALIAS_SYS_CAST2 (rawmemchr,
                         void *, (void const *__s, int __c_in),
                         void const *, (void const *__s, int __c_in));
+# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
+     && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+_GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in));
+_GL_CXXALIASWARN1 (rawmemchr, void const *, (void const *__s, int __c_in));
+# else
 _GL_CXXALIASWARN (rawmemchr);
+# endif
 #elif defined GNULIB_POSIXCHECK
 # undef rawmemchr
 # if HAVE_RAW_DECL_RAWMEMCHR
@@ -251,7 +270,13 @@
 _GL_CXXALIAS_SYS_CAST2 (strchrnul,
                         char *, (char const *__s, int __c_in),
                         char const *, (char const *__s, int __c_in));
+# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
+     && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+_GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in));
+_GL_CXXALIASWARN1 (strchrnul, char const *, (char const *__s, int __c_in));
+# else
 _GL_CXXALIASWARN (strchrnul);
+# endif
 #elif defined GNULIB_POSIXCHECK
 # undef strchrnul
 # if HAVE_RAW_DECL_STRCHRNUL
@@ -354,7 +379,14 @@
 _GL_CXXALIAS_SYS_CAST2 (strpbrk,
                         char *, (char const *__s, char const *__accept),
                         const char *, (char const *__s, char const *__accept));
+# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
+     && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+_GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept));
+_GL_CXXALIASWARN1 (strpbrk, char const *,
+                   (char const *__s, char const *__accept));
+# else
 _GL_CXXALIASWARN (strpbrk);
+# endif
 # if defined GNULIB_POSIXCHECK
 /* strpbrk() assumes the second argument is a list of single-byte characters.
    Even in this simple case, it does not work with multibyte strings if the
@@ -449,7 +481,14 @@
                         char *, (const char *haystack, const char *needle),
                         const char *, (const char *haystack, const char *needle));
 # endif
+# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
+     && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+_GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle));
+_GL_CXXALIASWARN1 (strstr, const char *,
+                   (const char *haystack, const char *needle));
+# else
 _GL_CXXALIASWARN (strstr);
+# endif
 #elif defined GNULIB_POSIXCHECK
 /* strstr() does not work with multibyte strings if the locale encoding is
    different from UTF-8:
@@ -489,7 +528,14 @@
                         char *, (const char *haystack, const char *needle),
                         const char *, (const char *haystack, const char *needle));
 # endif
+# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \
+     && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
+_GL_CXXALIASWARN1 (strcasestr, char *, (char *haystack, const char *needle));
+_GL_CXXALIASWARN1 (strcasestr, const char *,
+                   (const char *haystack, const char *needle));
+# else
 _GL_CXXALIASWARN (strcasestr);
+# endif
 #elif defined GNULIB_POSIXCHECK
 /* strcasestr() does not work with multibyte strings:
    It is a glibc extension, and glibc implements it only for unibyte