From 8be081fbbe1bb89c138db50209b0af06e877dc55 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sun, 6 Nov 2022 10:12:22 -0800 Subject: [PATCH 1/3] Fix Xcode 14 sprintf deprecation warning We use snprintf when stdc is set to C++11, however in C++98 mode we can't use variadic macros, and Xcode 14 complains about the use of sprintf. It should be safe however to use variadic macros on any remotely recent version of clang on Apple, unless -pedantic is defined which warns against the use of variadic macros in C++98 mode... This change fixes the problem for the builds that don't specify -pedantic, which is a problem for another day. --- src/pugixml.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index c63645b..4e72afe 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -143,6 +143,8 @@ using std::memset; # define PUGI__SNPRINTF(buf, ...) snprintf(buf, sizeof(buf), __VA_ARGS__) #elif defined(PUGI__MSVC_CRT_VERSION) && PUGI__MSVC_CRT_VERSION >= 1400 # define PUGI__SNPRINTF(buf, ...) _snprintf_s(buf, _countof(buf), _TRUNCATE, __VA_ARGS__) +#elif defined(__APPLE__) && __clang_major__ >= 14 && !defined(__STRICT_ANSI__) // Xcode 14 marks snprintf as deprecated while still using C++98 by default +# define PUGI__SNPRINTF(buf, ...) snprintf(buf, sizeof(buf), __VA_ARGS__) #else # define PUGI__SNPRINTF sprintf #endif From b6b747244e1b66f4906ef3920c53ae06a4400b26 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sun, 6 Nov 2022 10:21:35 -0800 Subject: [PATCH 2/3] Adjust the workaround for -pedantic mode and fix tests --- src/pugixml.cpp | 4 ++-- tests/test_document.cpp | 2 +- tests/test_dom_traverse.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 4e72afe..ab59c1e 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -143,8 +143,8 @@ using std::memset; # define PUGI__SNPRINTF(buf, ...) snprintf(buf, sizeof(buf), __VA_ARGS__) #elif defined(PUGI__MSVC_CRT_VERSION) && PUGI__MSVC_CRT_VERSION >= 1400 # define PUGI__SNPRINTF(buf, ...) _snprintf_s(buf, _countof(buf), _TRUNCATE, __VA_ARGS__) -#elif defined(__APPLE__) && __clang_major__ >= 14 && !defined(__STRICT_ANSI__) // Xcode 14 marks snprintf as deprecated while still using C++98 by default -# define PUGI__SNPRINTF(buf, ...) snprintf(buf, sizeof(buf), __VA_ARGS__) +#elif defined(__APPLE__) && __clang_major__ >= 14 // Xcode 14 marks snprintf as deprecated while still using C++98 by default +# define PUGI__SNPRINTF(buf, fmt, arg1, arg2) snprintf(buf, sizeof(buf), fmt, arg1, arg2) #else # define PUGI__SNPRINTF sprintf #endif diff --git a/tests/test_document.cpp b/tests/test_document.cpp index fca6bd9..2e2904d 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -737,7 +737,7 @@ struct temp_file { static int index = 0; - #if __cplusplus >= 201103 + #if __cplusplus >= 201103 || defined(__APPLE__) // Xcode 14 warns about use of sprintf in C++98 builds snprintf(path, sizeof(path), "%stempfile%d", test_runner::_temp_path, index++); #else sprintf(path, "%stempfile%d", test_runner::_temp_path, index++); diff --git a/tests/test_dom_traverse.cpp b/tests/test_dom_traverse.cpp index 29b4dfd..0c1e3af 100644 --- a/tests/test_dom_traverse.cpp +++ b/tests/test_dom_traverse.cpp @@ -796,7 +796,7 @@ struct test_walker: xml_tree_walker { char buf[32]; - #if __cplusplus >= 201103 + #if __cplusplus >= 201103 || defined(__APPLE__) // Xcode 14 warns about use of sprintf in C++98 builds snprintf(buf, sizeof(buf), "%d", depth()); #else sprintf(buf, "%d", depth()); From e11e0c965fe9008337d7a527e41b1e6eac1abeb1 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sun, 6 Nov 2022 13:47:53 -0800 Subject: [PATCH 3/3] Fix comment typo. --- src/pugixml.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index ab59c1e..ee8a666 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -143,7 +143,7 @@ using std::memset; # define PUGI__SNPRINTF(buf, ...) snprintf(buf, sizeof(buf), __VA_ARGS__) #elif defined(PUGI__MSVC_CRT_VERSION) && PUGI__MSVC_CRT_VERSION >= 1400 # define PUGI__SNPRINTF(buf, ...) _snprintf_s(buf, _countof(buf), _TRUNCATE, __VA_ARGS__) -#elif defined(__APPLE__) && __clang_major__ >= 14 // Xcode 14 marks snprintf as deprecated while still using C++98 by default +#elif defined(__APPLE__) && __clang_major__ >= 14 // Xcode 14 marks sprintf as deprecated while still using C++98 by default # define PUGI__SNPRINTF(buf, fmt, arg1, arg2) snprintf(buf, sizeof(buf), fmt, arg1, arg2) #else # define PUGI__SNPRINTF sprintf