From 04c4355c8e3b7198d3765da7a552ed8d5a9e26c2 Mon Sep 17 00:00:00 2001 From: Olivier BICHLER <olivier.bichler@cea.fr> Date: Wed, 7 Feb 2024 14:54:49 +0100 Subject: [PATCH] Better suppress warning --- include/aidge/utils/Formatting.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/aidge/utils/Formatting.hpp b/include/aidge/utils/Formatting.hpp index 8f572a867..e96e87e35 100644 --- a/include/aidge/utils/Formatting.hpp +++ b/include/aidge/utils/Formatting.hpp @@ -20,12 +20,16 @@ namespace Aidge { // The code snippet below is licensed under CC0 1.0. template<typename ... Args> std::string stringFormat(const std::string& format, Args... args) { +#if defined(__clang__) +#elif defined(__GNUC__) || defined(__GNUG__) // Disable security warning on GCC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-security" +#elif defined(_MSC_VER) // Disable security warning on MSVC #pragma warning(push) #pragma warning(disable : 4774) +#endif int size_s = std::snprintf(nullptr, 0, format.c_str(), args...) + 1; // Extra space for '\0' if (size_s <= 0) { std::printf("Error during formatting."); @@ -35,8 +39,12 @@ std::string stringFormat(const std::string& format, Args... args) { std::unique_ptr<char[]> buf(new char[size]); std::snprintf(buf.get(), size, format.c_str(), args...); return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside -#pragma warning(pop) +#if defined(__clang__) +#elif defined(__GNUC__) || defined(__GNUG__) #pragma GCC diagnostic pop +#elif defined(_MSC_VER) +#pragma warning(pop) +#endif } /** -- GitLab