From c55c191aba13a9f35da57dd8bf932c3947ff61b2 Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Fri, 17 Oct 2025 15:05:22 +0200 Subject: [PATCH] Fix -Wunknown-pragmas warnings --- test/base-stacktrace.cpp | 16 ++++++++------- tools/mkclass/classcompiler.cpp | 36 +++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/test/base-stacktrace.cpp b/test/base-stacktrace.cpp index ecee54a1f..23fe2edf1 100644 --- a/test/base-stacktrace.cpp +++ b/test/base-stacktrace.cpp @@ -20,13 +20,14 @@ using namespace icinga; * should be printed. If it looks somewhat meaningful, you can probably ignore a failure of this test case. */ -#ifndef _MSC_VER +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC push_options -#pragma GCC optimize ("O0") +#pragma GCC optimize("O0") +#elif defined(__clang__) #pragma clang optimize off -#else /* _MSC_VER */ +#elif defined(_MSC_VER) #pragma optimize("", off) -#endif /* _MSC_VER */ +#endif BOOST_AUTO_TEST_SUITE(base_stacktrace) @@ -66,9 +67,10 @@ BOOST_AUTO_TEST_CASE(stacktrace) BOOST_AUTO_TEST_SUITE_END() -#ifndef _MSC_VER +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC pop_options +#elif defined(__clang__) #pragma clang optimize on -#else /* _MSC_VER */ +#elif defined(_MSC_VER) #pragma optimize("", on) -#endif /* _MSC_VER */ +#endif diff --git a/tools/mkclass/classcompiler.cpp b/tools/mkclass/classcompiler.cpp index 9a9f9b633..e264e6b33 100644 --- a/tools/mkclass/classcompiler.cpp +++ b/tools/mkclass/classcompiler.cpp @@ -1477,26 +1477,32 @@ void ClassCompiler::CompileStream(const std::string& path, std::istream& input, << "#include \"base/logger.hpp\"" << std::endl << "#include \"base/function.hpp\"" << std::endl << "#include \"base/configobject.hpp\"" << std::endl - << "#include \"base/configtype.hpp\"" << std::endl - << "#ifdef _MSC_VER" << std::endl - << "#pragma warning( push )" << std::endl - << "#pragma warning( disable : 4244 )" << std::endl - << "#pragma warning( disable : 4800 )" << std::endl - << "#else /* _MSC_VER */" << std::endl - << "#pragma GCC diagnostic push" << std::endl - << "#pragma GCC diagnostic ignored \"-Wunused-parameter\"" << std::endl - << "#pragma GCC diagnostic ignored \"-Wunused-variable\"" << std::endl - << "#endif /* _MSC_VER */" << std::endl << std::endl; + << "#include \"base/configtype.hpp\"" << std::endl; +#ifdef _MSC_VER + oimpl << "#pragma warning( push )" << std::endl + << "#pragma warning( disable : 4244 )" << std::endl + << "#pragma warning( disable : 4800 )" << std::endl; +#elif defined(__GNUC__) && !defined(__clang__) + oimpl << "#pragma GCC diagnostic push" << std::endl + << "#pragma GCC diagnostic ignored \"-Wunused-parameter\"" << std::endl + << "#pragma GCC diagnostic ignored \"-Wunused-variable\"" << std::endl; +#elif defined(__clang__) + oimpl << "#pragma clang diagnostic push" << std::endl + << "#pragma clang diagnostic ignored \"-Wunused-parameter\"" << std::endl + << "#pragma clang diagnostic ignored \"-Wunused-variable\"" << std::endl; +#endif /* _MSC_VER */ ClassCompiler ctx(path, input, oimpl, oheader); ctx.Compile(); oheader << "#endif /* " << guard_name << " */" << std::endl; - oimpl << "#ifdef _MSC_VER" << std::endl - << "#pragma warning ( pop )" << std::endl - << "#else /* _MSC_VER */" << std::endl - << "#pragma GCC diagnostic pop" << std::endl - << "#endif /* _MSC_VER */" << std::endl; +#ifdef _MSC_VER + oimpl << "#pragma warning ( pop )" << std::endl; +#elif defined(__GNUC__) && !defined(__clang__) + oimpl << "#pragma GCC diagnostic pop" << std::endl; +#elif defined(__clang__) + oimpl << "#pragma clang diagnostic pop" << std::endl; +#endif /* _MSC_VER */ }