Hi Bruno,

The warnings say:

>     ../gllib/string.h:809:20: error: declaration of 'memchr' has a different 
> language linkage
>       809 | _GL_CXXALIASWARN1 (memchr, void *,
>           |                    ^
>     /usr/include/string.h:94:1: note: previous definition is here
>        94 | memchr (void *__s, int __c, size_t __n) __THROW
>           | ^

Initially looking at glibc's string.h on my system I had suspicions of
the following code in string.h:

    /* Tell the caller that we provide correct C++ prototypes.  */
    #if defined __cplusplus && (__GNUC_PREREQ (4, 4) \
                            || __glibc_clang_prereq (3, 5))
    # define __CORRECT_ISO_CPP_STRING_H_PROTO
    #endif
    [...]
    #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
    extern "C++"
    {
    extern void *memchr (void *__s, int __c, size_t __n)
        __THROW __asm ("memchr") __attribute_pure__ __nonnull ((1));
    extern const void *memchr (const void *__s, int __c, size_t __n)
        __THROW __asm ("memchr") __attribute_pure__ __nonnull ((1));
    [...]

Upon looking further I see that someone else ran into errors like this
using clang++ in 2021 [1]. AFAIK it was never resolved but the archives
split replies by month I think. So maybe I am wrong.

Does this sound reasonable to you? I have attached a patch that should
fix the testdir of all modules while using clang++.

Those _GL_CXXALIASWARN1, etc. macros sort of go over my head so sorry if
I am totally off mark.

Collin

[1] https://lists.gnu.org/archive/html/bug-gnulib/2021-01/msg00206.html

diff --git a/lib/string.in.h b/lib/string.in.h
index 44ec2e7ecd..8b084ae198 100644
--- a/lib/string.in.h
+++ b/lib/string.in.h
@@ -288,14 +288,14 @@ _GL_CXXALIAS_SYS_CAST2 (memchr,
 # endif
 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
-         || defined __clang__)
+         || (defined __clang__ && !defined __CORRECT_ISO_CPP_STRING_H_PROTO))
 _GL_CXXALIASWARN1 (memchr, void *,
                    (void *__s, int __c, size_t __n)
                    _GL_ATTRIBUTE_NOTHROW);
 _GL_CXXALIASWARN1 (memchr, void const *,
                    (void const *__s, int __c, size_t __n)
                    _GL_ATTRIBUTE_NOTHROW);
-# elif __GLIBC__ >= 2
+# elif __GLIBC__ >= 2 && !(defined __clang__ && defined __CORRECT_ISO_CPP_STRING_H_PROTO)
 _GL_CXXALIASWARN (memchr);
 # endif
 #elif defined GNULIB_POSIXCHECK
@@ -393,14 +393,14 @@ _GL_CXXALIAS_SYS_CAST2 (memrchr,
                         void const *, (void const *, int, size_t));
 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
-         || defined __clang__)
+         || (defined __clang__ && !defined __CORRECT_ISO_CPP_STRING_H_PROTO))
 _GL_CXXALIASWARN1 (memrchr, void *,
                    (void *, int, size_t)
                    _GL_ATTRIBUTE_NOTHROW);
 _GL_CXXALIASWARN1 (memrchr, void const *,
                    (void const *, int, size_t)
                    _GL_ATTRIBUTE_NOTHROW);
-# elif __GLIBC__ >= 2
+# elif __GLIBC__ >= 2 && !(defined __clang__ && defined __CORRECT_ISO_CPP_STRING_H_PROTO)
 _GL_CXXALIASWARN (memrchr);
 # endif
 #elif defined GNULIB_POSIXCHECK
@@ -455,14 +455,14 @@ _GL_CXXALIAS_SYS_CAST2 (rawmemchr,
                         void const *, (void const *__s, int __c_in));
 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
-         || defined __clang__)
+         || (defined __clang__ && !defined __CORRECT_ISO_CPP_STRING_H_PROTO))
 _GL_CXXALIASWARN1 (rawmemchr, void *,
                    (void *__s, int __c_in)
                    _GL_ATTRIBUTE_NOTHROW);
 _GL_CXXALIASWARN1 (rawmemchr, void const *,
                    (void const *__s, int __c_in)
                    _GL_ATTRIBUTE_NOTHROW);
-# else
+# elif __GLIBC__ >= 2 && !(defined __clang__ && defined __CORRECT_ISO_CPP_STRING_H_PROTO)
 _GL_CXXALIASWARN (rawmemchr);
 # endif
 #elif defined GNULIB_POSIXCHECK
@@ -580,14 +580,14 @@ _GL_CXXALIAS_SYS_CAST2 (strchrnul,
 # endif
 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
-         || defined __clang__)
+         || (defined __clang__ && !defined __CORRECT_ISO_CPP_STRING_H_PROTO))
 _GL_CXXALIASWARN1 (strchrnul, char *,
                    (char *__s, int __c_in)
                    _GL_ATTRIBUTE_NOTHROW);
 _GL_CXXALIASWARN1 (strchrnul, char const *,
                    (char const *__s, int __c_in)
                    _GL_ATTRIBUTE_NOTHROW);
-# elif __GLIBC__ >= 2
+# elif __GLIBC__ >= 2 && !(defined __clang__ && defined __CORRECT_ISO_CPP_STRING_H_PROTO)
 _GL_CXXALIASWARN (strchrnul);
 # endif
 #elif defined GNULIB_POSIXCHECK
@@ -819,14 +819,14 @@ _GL_CXXALIAS_SYS_CAST2 (strpbrk,
                         const char *, (char const *__s, char const *__accept));
 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
-         || defined __clang__)
+         || (defined __clang__ && !defined __CORRECT_ISO_CPP_STRING_H_PROTO))
 _GL_CXXALIASWARN1 (strpbrk, char *,
                    (char *__s, char const *__accept)
                    _GL_ATTRIBUTE_NOTHROW);
 _GL_CXXALIASWARN1 (strpbrk, char const *,
                    (char const *__s, char const *__accept)
                    _GL_ATTRIBUTE_NOTHROW);
-# elif __GLIBC__ >= 2
+# elif __GLIBC__ >= 2 && !(defined __clang__ && defined __CORRECT_ISO_CPP_STRING_H_PROTO)
 _GL_CXXALIASWARN (strpbrk);
 # endif
 # if defined GNULIB_POSIXCHECK
@@ -931,14 +931,14 @@ _GL_CXXALIAS_SYS_CAST2 (strstr,
 # endif
 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
-         || defined __clang__)
+         || (defined __clang__ && !defined __CORRECT_ISO_CPP_STRING_H_PROTO))
 _GL_CXXALIASWARN1 (strstr, char *,
                    (char *haystack, const char *needle)
                    _GL_ATTRIBUTE_NOTHROW);
 _GL_CXXALIASWARN1 (strstr, const char *,
                    (const char *haystack, const char *needle)
                    _GL_ATTRIBUTE_NOTHROW);
-# elif __GLIBC__ >= 2
+# elif __GLIBC__ >= 2 && !(defined __clang__ && defined __CORRECT_ISO_CPP_STRING_H_PROTO)
 _GL_CXXALIASWARN (strstr);
 # endif
 #elif defined GNULIB_POSIXCHECK
@@ -984,14 +984,14 @@ _GL_CXXALIAS_SYS_CAST2 (strcasestr,
 # endif
 # if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
      && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) \
-         || defined __clang__)
+         || (defined __clang__ && !defined __CORRECT_ISO_CPP_STRING_H_PROTO))
 _GL_CXXALIASWARN1 (strcasestr, char *,
                    (char *haystack, const char *needle)
                    _GL_ATTRIBUTE_NOTHROW);
 _GL_CXXALIASWARN1 (strcasestr, const char *,
                    (const char *haystack, const char *needle)
                    _GL_ATTRIBUTE_NOTHROW);
-# elif __GLIBC__ >= 2
+# elif __GLIBC__ >= 2 && !(defined __clang__ && defined __CORRECT_ISO_CPP_STRING_H_PROTO)
 _GL_CXXALIASWARN (strcasestr);
 # endif
 #elif defined GNULIB_POSIXCHECK

Reply via email to