[PATCH 04/27] gdb/testsuite: Compile with -Wno-deprecated-declarations on windows-msvc

Pedro Alves <[email protected]> Thu, 23 Jul 2026 14:00:55 +0100
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
Several testcases hit compilation errors like:

 output is .../testsuite/gdb.base/callfuncs.c:231:3: warning: 'strcpy' is deprecated: This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [-Wdeprecated-declarations]
   231 |   strcpy (buf, tstruct.a);
       |   ^
 C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\string.h:130:1: note: 'strcpy' has been explicitly marked deprecated here
   130 | __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1(
       | ^
 C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt.h:874:5: note: expanded from macro '__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1'
   874 |     __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX(_ReturnType, _ReturnPolicy, _DeclSpec, _FuncName, _FuncName##_s, _DstType, _SalAttributeDst, _DstType, _Dst, _TType1, _TArg1)
       |     ^
 C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt.h:1933:17: note: expanded from macro '__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX'
  1933 |                 _CRT_INSECURE_DEPRECATE(_SecureFuncName) _DeclSpec _ReturnType __cdecl _FuncName(_SalAttributeDst _DstType *_Dst, _TType1 _TArg1);
       |                 ^
 C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\vcruntime.h:368:55: note: expanded from macro '_CRT_INSECURE_DEPRECATE'
   368 |         #define _CRT_INSECURE_DEPRECATE(_Replacement) _CRT_DEPRECATE_TEXT(    \
       |                                                       ^
 C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\vcruntime.h:358:47: note: expanded from macro '_CRT_DEPRECATE_TEXT'
   358 | #define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
       |                                               ^

Fix this by always compiling C/C++ tests with
-Wno-deprecated-declarations on windows-msvc targets.

Change-Id: I9058f70c69a7b9e5ebf2f38b84c7e35df92ddc0d
---
 gdb/testsuite/lib/gdb.exp | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index b4046c402d4..fb9f29ee03d 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6671,6 +6671,21 @@ proc gdb_compile {source dest type options} {
 	    || [test_compiler_info {icc-20-21-[7-9]}]} {
 	    lappend new_options "additional_flags=-diag-disable=10441"
 	}
+
+	if {[istarget "*-*-windows-msvc*"]
+	    && ([test_compiler_info "clang-*"]
+		|| [test_compiler_info "gcc-*"])} {
+	    # Compiling with the MSVC headers results in:
+	    #
+	    #  warning: 'strcpy' is deprecated: This function or variable may be unsafe.
+	    #  Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
+	    #  See online help for details. [-Wdeprecated-declarations]
+	    #
+	    # We get the same warning for strcpy, getenv, fopen,
+	    # wcscat, and others, throughout the testsuite.  Easier to
+	    # just disable globally.
+	    lappend new_options "additional_flags=-Wno-deprecated-declarations"
+	}
     }
 
     # If the 'build-id' option is used, then ensure that we generate a
-- 
2.54.0