bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

string: Fix compilation error in C++ mode


From: Bruno Haible
Subject: string: Fix compilation error in C++ mode
Date: Sun, 10 May 2020 18:17:40 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-177-generic; KDE/5.18.0; x86_64; ; )

When building a testdir of all of gnulib with GCC 10.1.0, I see these
compilation errors:

In file included from ../../gltests/test-list-c++.cc:23:
../gllib/string.h:806:1: error: type of 'strchr' is unknown
  806 | _GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character 
strings "
      | ^~~~~~~~~~~~~~~
../gllib/string.h:806:1: error: 'int strchr' redeclared as different kind of 
entity
  806 | _GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character 
strings "
      | ^~~~~~~~~~~~~~~
In file included from ../gllib/string.h:41,
                 from ../../gltests/test-list-c++.cc:23:
/usr/include/string.h:224:1: note: previous declaration 'const char* 
strchr(const char*, int)'
  224 | strchr (const char *__s, int __c) __THROW
      | ^~~~~~
In file included from ../../gltests/test-list-c++.cc:23:
../gllib/string.h:1000:1: error: type of 'strpbrk' is unknown
 1000 | _GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character 
strings "
      | ^~~~~~~~~~~~~~~
../gllib/string.h:1000:1: error: 'int strpbrk' redeclared as different kind of 
entity
 1000 | _GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character 
strings "
      | ^~~~~~~~~~~~~~~
In file included from ../gllib/string.h:41,
                 from ../../gltests/test-list-c++.cc:23:
/usr/include/string.h:303:1: note: previous declaration 'const char* 
strpbrk(const char*, const char*)'
  303 | strpbrk (const char *__s, const char *__accept) __THROW
      | ^~~~~~~
In file included from ../../gltests/test-list-c++.cc:23:
../gllib/string.h:1027:1: error: type of 'strrchr' is unknown
 1027 | _GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character 
strings "
      | ^~~~~~~~~~~~~~~
../gllib/string.h:1027:1: error: 'int strrchr' redeclared as different kind of 
entity
 1027 | _GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character 
strings "
      | ^~~~~~~~~~~~~~~
In file included from ../gllib/string.h:41,
                 from ../../gltests/test-list-c++.cc:23:
/usr/include/string.h:251:1: note: previous declaration 'const char* 
strrchr(const char*, int)'
  251 | strrchr (const char *__s, int __c) __THROW
      | ^~~~~~~

This patch fixes it.


2020-05-10  Bruno Haible  <address@hidden>

        string: Fix compilation error in C++ mode.
        * lib/warn-on-use.h (_GL_WARN_ON_USE_CXX): In C mode, use plain
        _GL_WARN_ON_USE.
        * lib/string.in.h (strchr, strpbrk, strrchr): Use _GL_WARN_ON_USE_CXX
        instead of _GL_WARN_ON_USE.

diff --git a/lib/string.in.h b/lib/string.in.h
index d601450..77ccf94 100644
--- a/lib/string.in.h
+++ b/lib/string.in.h
@@ -334,9 +334,10 @@ _GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
    GB18030 and the character to be searched is a digit.  */
 # undef strchr
 /* Assume strchr is always declared.  */
-_GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings "
-                 "in some multibyte locales - "
-                 "use mbschr if you care about internationalization");
+_GL_WARN_ON_USE_CXX (strchr, const char *, (const char *, int),
+                     "strchr cannot work correctly on character strings "
+                     "in some multibyte locales - "
+                     "use mbschr if you care about internationalization");
 #endif
 
 /* Find the first occurrence of C in S or the final NUL byte.  */
@@ -528,15 +529,17 @@ _GL_CXXALIASWARN (strpbrk);
    locale encoding is GB18030 and one of the characters to be searched is a
    digit.  */
 #  undef strpbrk
-_GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character strings "
-                 "in multibyte locales - "
-                 "use mbspbrk if you care about internationalization");
+_GL_WARN_ON_USE_CXX (strpbrk, const char *, (const char *, const char *),
+                     "strpbrk cannot work correctly on character strings "
+                     "in multibyte locales - "
+                     "use mbspbrk if you care about internationalization");
 # endif
 #elif defined GNULIB_POSIXCHECK
 # undef strpbrk
 # if HAVE_RAW_DECL_STRPBRK
-_GL_WARN_ON_USE (strpbrk, "strpbrk is unportable - "
-                 "use gnulib module strpbrk for portability");
+_GL_WARN_ON_USE_CXX (strpbrk, const char *, (const char *, const char *),
+                     "strpbrk is unportable - "
+                     "use gnulib module strpbrk for portability");
 # endif
 #endif
 
@@ -555,9 +558,10 @@ _GL_WARN_ON_USE (strspn, "strspn cannot work correctly on 
character strings "
    GB18030 and the character to be searched is a digit.  */
 # undef strrchr
 /* Assume strrchr is always declared.  */
-_GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character strings "
-                 "in some multibyte locales - "
-                 "use mbsrchr if you care about internationalization");
+_GL_WARN_ON_USE_CXX (strrchr, const char *, (const char *, int),
+                     "strrchr cannot work correctly on character strings "
+                     "in some multibyte locales - "
+                     "use mbsrchr if you care about internationalization");
 #endif
 
 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
diff --git a/lib/warn-on-use.h b/lib/warn-on-use.h
index 1cf5770..291e709 100644
--- a/lib/warn-on-use.h
+++ b/lib/warn-on-use.h
@@ -100,23 +100,28 @@ _GL_WARN_EXTERN_C int _gl_warn_on_use
 #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.
+   is like _GL_WARN_ON_USE (function, "string"), except that in C++ mode 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__)
+# if !defined __cplusplus
 #  define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+     _GL_WARN_ON_USE (function, msg)
+# else
+#  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)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+#  elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
 /* Verify the existence of the function.  */
-#  define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+#   define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) 
\
 extern rettype function parameters_and_attributes
-# else /* Unsupported.  */
-#  define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+#  else /* Unsupported.  */
+#   define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) 
\
 _GL_WARN_EXTERN_C int _gl_warn_on_use
+#  endif
 # endif
 #endif
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]