diff --git a/include/boost/core/type_name.hpp b/include/boost/core/type_name.hpp index 53c0224..e39dc28 100644 --- a/include/boost/core/type_name.hpp +++ b/include/boost/core/type_name.hpp @@ -185,14 +185,23 @@ template std::string array_template_name() # pragma warning( disable: 4996 ) #endif +// Use snprintf if available as some compilers (clang 14.0) issue deprecation warnings for sprintf +#if ( defined(_MSC_VER) && _MSC_VER < 1900 ) || ( defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) ) +# define BOOST_CORE_SNPRINTF(buffer, format, arg) std::sprintf(buffer, format, arg) +#else +# define BOOST_CORE_SNPRINTF(buffer, format, arg) std::snprintf(buffer, sizeof(buffer)/sizeof(buffer[0]), format, arg) +#endif + inline std::string tn_to_string( std::size_t n ) { char buffer[ 32 ]; - std::sprintf( buffer, "%lu", static_cast< unsigned long >( n ) ); + BOOST_CORE_SNPRINTF( buffer, "%lu", static_cast< unsigned long >( n ) ); return buffer; } +#undef BOOST_CORE_SNPRINTF + #if defined(BOOST_MSVC) # pragma warning( pop ) #endif