Fix compilation error with glibc >= 2.10 and g++ >= 4.4.
authorBruno Haible <bruno@clisp.org>
Sat, 13 Mar 2010 11:06:23 +0000 (12:06 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 13 Mar 2010 11:06:23 +0000 (12:06 +0100)
ChangeLog
build-aux/c++defs.h
build-aux/warn-on-use.h
lib/string.in.h

index fa172b9..efd717b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index 138daf2..31a7d63 100644 (file)
 
 /* _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.")
     _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 */
index 3d93a9e..d33cfe6 100644 (file)
@@ -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 __typeof__ (function) function __attribute__ ((__warning__ (message)))
 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
index 681db17..4788a19 100644 (file)
@@ -73,7 +73,14 @@ _GL_CXXALIAS_SYS_CAST2 (memchr,
                         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_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t)
 _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_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in)
 _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_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in)
 _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_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept)
 _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 @@ _GL_CXXALIAS_SYS_CAST2 (strstr,
                         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 @@ _GL_CXXALIAS_SYS_CAST2 (strcasestr,
                         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