Fix C++ debug tests

Message ID AM5PR0802MB26104FB45A8DAA0359769B2383450@AM5PR0802MB2610.eurprd08.prod.outlook.com
State Superseded
Headers

Commit Message

Wilco Dijkstra Feb. 9, 2017, 3:10 p.m. UTC
  ping


From: Wilco Dijkstra
Sent: 20 December 2016 15:37
To: libc-alpha@sourceware.org
Cc: nd
Subject: [PATCH] Fix C++ debug tests
    
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).  As a workaround for now, add extern "C" {} to the C++ debug tests.

C++ debug tests now build and pass.

ChangeLog:
2016-12-21  Wilco Dijkstra  <wdijkstr@arm.com>

        * debug/tst-chk4.cc: Add extern "C".
        * debug/tst-chk5.cc: Likewise.
        * debug/tst-chk6.cc: Likewise.
        * debug/tst-lfschk4.cc: Likewise.
        * debug/tst-lfschk5.cc: Likewise.
        * debug/tst-lfschk6.cc: Likewise.
--
  

Comments

Joseph Myers Feb. 9, 2017, 5:17 p.m. UTC | #1
On Thu, 9 Feb 2017, Wilco Dijkstra wrote:

> 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).  As a workaround for now, 
> add extern "C" {} to the C++ debug tests.

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).
  

Patch

diff --git a/debug/tst-chk4.cc b/debug/tst-chk4.cc
index c82e6aac86038791309486d6d40a29f5897e9755..75c2de659460c555a0956eeb1b49c4d6a1615f36 100644
--- a/debug/tst-chk4.cc
+++ b/debug/tst-chk4.cc
@@ -1 +1,3 @@ 
+extern "C" {
 #include "tst-chk1.c"
+}
diff --git a/debug/tst-chk5.cc b/debug/tst-chk5.cc
index be37ce2d22f0760a880003f39b8a67a471530f82..95b3108d8349210420b88388ec3c406fdfccb00c 100644
--- a/debug/tst-chk5.cc
+++ b/debug/tst-chk5.cc
@@ -1,2 +1,4 @@ 
+extern "C" {
 #define _FORTIFY_SOURCE 1
 #include "tst-chk1.c"
+}
diff --git a/debug/tst-chk6.cc b/debug/tst-chk6.cc
index 38b8e4fb360ba72255eb462f98c97dd4e1b56b55..fcaf0e1035afcca92e5371bc6b6b7ae4ad96c345 100644
--- a/debug/tst-chk6.cc
+++ b/debug/tst-chk6.cc
@@ -1,2 +1,4 @@ 
+extern "C" {
 #define _FORTIFY_SOURCE 2
 #include "tst-chk1.c"
+}
diff --git a/debug/tst-lfschk4.cc b/debug/tst-lfschk4.cc
index f3e6d47d5e4484c3735c8d1fe2a5f847279d54cb..e2ec17d9705adc70868ea9fa3e158a794cb2058a 100644
--- a/debug/tst-lfschk4.cc
+++ b/debug/tst-lfschk4.cc
@@ -1,2 +1,4 @@ 
+extern "C" {
 #define _FILE_OFFSET_BITS 64
 #include "tst-chk1.c"
+}
diff --git a/debug/tst-lfschk5.cc b/debug/tst-lfschk5.cc
index 95d4db1d32d2eeb36cdf94ffe062350296242581..df9549f5c7bcb744eca7b3e5cbfb35376068a938 100644
--- a/debug/tst-lfschk5.cc
+++ b/debug/tst-lfschk5.cc
@@ -1,2 +1,4 @@ 
+extern "C" {
 #define _FILE_OFFSET_BITS 64
 #include "tst-chk2.c"
+}
diff --git a/debug/tst-lfschk6.cc b/debug/tst-lfschk6.cc
index 50a1ae1258f1553d11731e2ff45d18422e16e20c..bab9fa803802c478064943569189ea2d1f026ab3 100644
--- a/debug/tst-lfschk6.cc
+++ b/debug/tst-lfschk6.cc
@@ -1,2 +1,4 @@ 
+extern "C" {
 #define _FILE_OFFSET_BITS 64
 #include "tst-chk3.c"
+}