Fix C++ debug tests

Message ID AM5PR0802MB2610543F3A2C34C83A3AC7BD83580@AM5PR0802MB2610.eurprd08.prod.outlook.com
State Committed
Headers

Commit Message

Wilco Dijkstra Feb. 14, 2017, 1:07 p.m. UTC
  Joseph Myers wrote:
> I think extern "C" belongs around specific declarations in headers, not 
> around whole source files.  I'd suggest disabling the internal 
> declarations if __cplusplus instead (just as they are disabled for 
> _ISOMAC).

Yes that's a good idea. I've updated the patch to change the header instead:

The internal header include/string.h does not work in C++: it causes link errors
in several C++ debug tests when any of the functions it declares are called.
The best option would be to not use internal headers for tests (unless explicitly 
needed).  Add guards so that it is safe to use include/string.h from C++.

ChangeLog:
2017-02-14  Wilco Dijkstra  <wdijkstr@arm.com>

	* include/string.h: Add __cplusplus check.

--
  

Comments

Joseph Myers Feb. 14, 2017, 6:42 p.m. UTC | #1
On Tue, 14 Feb 2017, Wilco Dijkstra wrote:

> Joseph Myers wrote:
> > I think extern "C" belongs around specific declarations in headers, not 
> > around whole source files.  I'd suggest disabling the internal 
> > declarations if __cplusplus instead (just as they are disabled for 
> > _ISOMAC).
> 
> Yes that's a good idea. I've updated the patch to change the header instead:
> 
> The internal header include/string.h does not work in C++: it causes link errors
> in several C++ debug tests when any of the functions it declares are called.
> The best option would be to not use internal headers for tests (unless explicitly 
> needed).  Add guards so that it is safe to use include/string.h from C++.
> 
> ChangeLog:
> 2017-02-14  Wilco Dijkstra  <wdijkstr@arm.com>
> 
> 	* include/string.h: Add __cplusplus check.

OK.
  

Patch

diff --git a/include/string.h b/include/string.h
index 07389f327886bccc3ba30a0056c25a309c72079c..45eca3c11c8a72dacc26d4b9ea27a0642b17677f 100644
--- a/include/string.h
+++ b/include/string.h
@@ -1,6 +1,6 @@ 
 #ifndef _STRING_H
 
-#ifndef _ISOMAC
+#if !defined _ISOMAC && !defined __cplusplus
 #include <sys/types.h>
 
 extern void *__memccpy (void *__dest, const void *__src,
@@ -53,7 +53,7 @@  extern char *__strerror_r (int __errnum, char *__buf, size_t __buflen);
    above are defined as macros in the headers.  */
 #include <string/string.h>
 
-#ifndef _ISOMAC
+#if !defined _ISOMAC && !defined __cplusplus
 extern __typeof (strcoll_l) __strcoll_l;
 extern __typeof (strxfrm_l) __strxfrm_l;
 extern __typeof (strcasecmp_l) __strcasecmp_l;