Add MSVC compiler flag. (see #2094)

This commit is contained in:
HoseynHeydari 2022-04-14 17:23:59 +04:30
parent c665fd7f50
commit e3aaa40fe7
25 changed files with 66 additions and 42 deletions

View File

@ -10,11 +10,12 @@
#ifndef CATCH_OPTIMIZER_HPP_INCLUDED
#define CATCH_OPTIMIZER_HPP_INCLUDED
#if defined(_MSC_VER)
#include <catch2/internal/catch_compiler_capabilities.hpp>
#if defined(CATCH_COMPILER_MSC)
# include <atomic> // atomic_thread_fence
#endif
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>
#include <type_traits>
@ -33,7 +34,7 @@ namespace Catch {
namespace Detail {
inline void optimizer_barrier() { keep_memory(); }
} // namespace Detail
#elif defined(_MSC_VER)
#elif defined(CATCH_COMPILER_MSC)
#pragma optimize("", off)
template <typename T>

View File

@ -6,7 +6,9 @@
// SPDX-License-Identifier: BSL-1.0
#include <catch2/catch_config.hpp>
#include <catch2/catch_user_config.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_enforce.hpp>
#include <catch2/internal/catch_stream.hpp>
#include <catch2/internal/catch_stringref.hpp>
@ -68,14 +70,14 @@ namespace Catch {
// during test, Bazel will not generate a default XML output.
// This allows the XML output file to contain higher level of detail
// than what is possible otherwise.
# if defined( _MSC_VER )
# if defined( CATCH_COMPILER_MSC )
// On Windows getenv throws a warning as there is no input validation,
// since the key is hardcoded, this should not be an issue.
# pragma warning( push )
# pragma warning( disable : 4996 )
# endif
const auto bazelOutputFilePtr = std::getenv( "XML_OUTPUT_FILE" );
# if defined( _MSC_VER )
# if defined( CATCH_COMPILER_MSC )
# pragma warning( pop )
# endif
if ( bazelOutputFilePtr != nullptr ) {

View File

@ -25,7 +25,7 @@
#include <string_view>
#endif
#ifdef _MSC_VER
#ifdef CATCH_COMPILER_MSC
#pragma warning(push)
#pragma warning(disable:4180) // We attempt to stream a function (address) by const&, which MSVC complains about but is harmless
#endif
@ -625,7 +625,7 @@ struct ratio_string<std::milli> {
static std::string convert(std::chrono::time_point<std::chrono::system_clock, Duration> const& time_point) {
auto converted = std::chrono::system_clock::to_time_t(time_point);
#ifdef _MSC_VER
#ifdef CATCH_COMPILER_MSC
std::tm timeInfo = {};
gmtime_s(&timeInfo, &converted);
#else
@ -636,7 +636,7 @@ struct ratio_string<std::milli> {
char timeStamp[timeStampSize];
const char * const fmt = "%Y-%m-%dT%H:%M:%SZ";
#ifdef _MSC_VER
#ifdef CATCH_COMPILER_MSC
std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
#else
std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
@ -660,7 +660,7 @@ namespace Catch { \
#define CATCH_REGISTER_ENUM( enumName, ... ) INTERNAL_CATCH_REGISTER_ENUM( enumName, __VA_ARGS__ )
#ifdef _MSC_VER
#ifdef CATCH_COMPILER_MSC
#pragma warning(pop)
#endif

View File

@ -32,10 +32,14 @@
#define CATCH_COMPILER_GCC
#endif
#if defined(__clang__) && !defined(_MSC_VER)
#if defined(__clang__)
#define CATCH_COMPILER_CLANG
#endif
#if defined(_MSC_VER) && !defined(__clang__)
#define CATCH_COMPILER_MSC
#endif
#ifdef __cplusplus
# if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
@ -164,7 +168,7 @@
////////////////////////////////////////////////////////////////////////////////
// Visual C++
#if defined(_MSC_VER)
#if defined(CATCH_COMPILER_MSC)
# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) )
# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) )

View File

@ -17,7 +17,9 @@
#ifndef CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED
#define CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED
#if defined(_MSC_VER)
#include <catch2/internal/catch_compiler_capabilities.hpp>
#if defined(CATCH_COMPILER_MSC)
# if _MSC_VER >= 1900 // Visual Studio 2015 or newer
# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
# endif

View File

@ -17,7 +17,7 @@
// for C++14 or C++ libraries with incomplete support.
// We also have to handle that MSVC std lib will happily provide these
// under older standards.
#if defined(CATCH_CPP17_OR_GREATER) || defined(_MSC_VER)
#if defined(CATCH_CPP17_OR_GREATER) || defined(CATCH_COMPILER_MSC)
// We are already using this header either way, so there shouldn't
// be much additional overhead in including it to get the feature

View File

@ -6,6 +6,8 @@
// SPDX-License-Identifier: BSL-1.0
#include <catch2/internal/catch_debugger.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_errno_guard.hpp>
#include <catch2/internal/catch_stream.hpp>
#include <catch2/internal/catch_platform.hpp>
@ -99,7 +101,7 @@
return false;
}
} // namespace Catch
#elif defined(_MSC_VER)
#elif defined(CATCH_COMPILER_MSC)
extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
namespace Catch {
bool isDebuggerActive() {

View File

@ -47,7 +47,7 @@ namespace Catch {
#define CATCH_TRAP() raise(SIGTRAP)
#endif
#elif defined(_MSC_VER)
#elif defined(CATCH_COMPILER_MSC)
#define CATCH_TRAP() __debugbreak()
#elif defined(__MINGW32__)
extern "C" __declspec(dllimport) void __stdcall DebugBreak();

View File

@ -15,7 +15,7 @@
#include <iosfwd>
#ifdef _MSC_VER
#ifdef CATCH_COMPILER_MSC
#pragma warning(push)
#pragma warning(disable:4389) // '==' : signed/unsigned mismatch
#pragma warning(disable:4018) // more "signed/unsigned mismatch"
@ -257,7 +257,7 @@ namespace Catch {
} // end namespace Catch
#ifdef _MSC_VER
#ifdef CATCH_COMPILER_MSC
#pragma warning(pop)
#endif
#ifdef CATCH_COMPILER_CLANG

View File

@ -6,6 +6,8 @@
// SPDX-License-Identifier: BSL-1.0
#include <catch2/internal/catch_output_redirect.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_enforce.hpp>
#include <cstdio>
@ -13,7 +15,7 @@
#include <sstream>
#if defined(CATCH_CONFIG_NEW_CAPTURE)
#if defined(_MSC_VER)
#if defined(CATCH_COMPILER_MSC)
#include <io.h> //_dup and _dup2
#define dup _dup
#define dup2 _dup2
@ -59,7 +61,7 @@ namespace Catch {
#if defined(CATCH_CONFIG_NEW_CAPTURE)
#if defined(_MSC_VER)
#if defined(CATCH_COMPILER_MSC)
TempFile::TempFile() {
if (tmpnam_s(m_buffer)) {
CATCH_RUNTIME_ERROR("Could not get a temp filename");
@ -87,7 +89,7 @@ namespace Catch {
std::fclose(m_file);
// We manually create the file on Windows only, on Linux
// it will be autodeleted
#if defined(_MSC_VER)
#if defined(CATCH_COMPILER_MSC)
std::remove(m_buffer);
#endif
}
@ -137,7 +139,7 @@ namespace Catch {
} // namespace Catch
#if defined(CATCH_CONFIG_NEW_CAPTURE)
#if defined(_MSC_VER)
#if defined(CATCH_COMPILER_MSC)
#undef dup
#undef dup2
#undef fileno

View File

@ -85,7 +85,7 @@ namespace Catch {
private:
std::FILE* m_file = nullptr;
#if defined(_MSC_VER)
#if defined(CATCH_COMPILER_MSC)
char m_buffer[L_tmpnam] = { 0 };
#endif
};

View File

@ -8,6 +8,8 @@
#ifndef CATCH_PLATFORM_HPP_INCLUDED
#define CATCH_PLATFORM_HPP_INCLUDED
#include <catch2/internal/catch_compiler_capabilities.hpp>
// See e.g.:
// https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/TargetConditionals.h.auto.html
#ifdef __APPLE__
@ -22,7 +24,7 @@
#elif defined(linux) || defined(__linux) || defined(__linux__)
# define CATCH_PLATFORM_LINUX
#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__)
#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(CATCH_COMPILER_MSC) || defined(__MINGW32__)
# define CATCH_PLATFORM_WINDOWS
#endif

View File

@ -7,11 +7,13 @@
// SPDX-License-Identifier: BSL-1.0
#include <catch2/internal/catch_random_number_generator.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
namespace Catch {
namespace {
#if defined(_MSC_VER)
#if defined(CATCH_COMPILER_MSC)
#pragma warning(push)
#pragma warning(disable:4146) // we negate uint32 during the rotate
#endif
@ -22,7 +24,7 @@ namespace {
return (val >> count) | (val << (-count & mask));
}
#if defined(_MSC_VER)
#if defined(CATCH_COMPILER_MSC)
#pragma warning(pop)
#endif

View File

@ -17,8 +17,10 @@
* of Catch2 has its own combined TU like this.
*/
#include <catch2/reporters/catch_reporter_helpers.hpp>
#include <catch2/interfaces/catch_interfaces_config.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_console_width.hpp>
#include <catch2/internal/catch_errno_guard.hpp>
#include <catch2/internal/catch_textflow.hpp>
@ -68,7 +70,7 @@ namespace Catch {
// Save previous errno, to prevent sprintf from overwriting it
ErrnoGuard guard;
#ifdef _MSC_VER
#ifdef CATCH_COMPILER_MSC
size_t printedLength = static_cast<size_t>(
sprintf_s( buffer, "%.3f", duration ) );
#else

View File

@ -23,7 +23,7 @@
#include <cstdio>
#if defined(_MSC_VER)
#if defined(CATCH_COMPILER_MSC)
#pragma warning(push)
#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch
// Note that 4062 (not all labels are handled and default is missing) is enabled
@ -711,7 +711,7 @@ void ConsoleReporter::printTestFilters() {
} // end namespace Catch
#if defined(_MSC_VER)
#if defined(CATCH_COMPILER_MSC)
#pragma warning(pop)
#endif

View File

@ -9,6 +9,7 @@
#include <catch2/reporters/catch_reporter_helpers.hpp>
#include <catch2/catch_tostring.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_string_manip.hpp>
#include <catch2/internal/catch_textflow.hpp>
#include <catch2/interfaces/catch_interfaces_config.hpp>
@ -28,7 +29,7 @@ namespace Catch {
std::time(&rawtime);
std::tm timeInfo = {};
#if defined (_MSC_VER) || defined (__MINGW32__)
#if defined (CATCH_COMPILER_MSC) || defined (__MINGW32__)
gmtime_s(&timeInfo, &rawtime);
#else
gmtime_r(&rawtime, &timeInfo);

View File

@ -10,12 +10,13 @@
#include <catch2/reporters/catch_reporter_helpers.hpp>
#include <catch2/interfaces/catch_interfaces_config.hpp>
#include <catch2/catch_test_spec.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_string_manip.hpp>
#include <catch2/internal/catch_list.hpp>
#include <catch2/catch_test_case_info.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>
#if defined(_MSC_VER)
#if defined(CATCH_COMPILER_MSC)
#pragma warning(push)
#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch
// Note that 4062 (not all labels are handled
@ -300,6 +301,6 @@ namespace Catch {
} // end namespace Catch
#if defined(_MSC_VER)
#if defined(CATCH_COMPILER_MSC)
#pragma warning(pop)
#endif

View File

@ -6,12 +6,13 @@
// SPDX-License-Identifier: BSL-1.0
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/internal/catch_enforce.hpp>
#include <catch2/internal/catch_case_insensitive_comparisons.hpp>
#include <catch2/internal/catch_optional.hpp>
#if defined(_MSC_VER)
#if defined(CATCH_COMPILER_MSC)
#pragma warning(push)
#pragma warning(disable:4702) // unreachable code in the macro expansions
#endif
@ -24,7 +25,7 @@ TEST_CASE("Check that our error handling macros throw the right exceptions", "[!
REQUIRE_NOTHROW([](){CATCH_ENFORCE(true, "");}());
}
#if defined(_MSC_VER)
#if defined(CATCH_COMPILER_MSC)
#pragma warning(pop) // unreachable code in the macro expansions
#endif

View File

@ -197,7 +197,7 @@ TEST_CASE("#1548", "[compilation]") {
inline static void synchronizing_callback( void * ) { }
}
#if defined (_MSC_VER)
#if defined (CATCH_COMPILER_MSC)
#pragma warning(push)
// The function pointer comparison below triggers warning because of
// calling conventions
@ -207,7 +207,7 @@ TEST_CASE("#1548", "[compilation]") {
TestClass test;
REQUIRE(utility::synchronizing_callback != test.testMethod_uponComplete_arg);
}
#if defined (_MSC_VER)
#if defined (CATCH_COMPILER_MSC)
#pragma warning(pop)
#endif

View File

@ -230,7 +230,7 @@ TEST_CASE( "Comparisons with int literals don't warn when mixing signed/ unsigne
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#ifdef _MSC_VER
#ifdef CATCH_COMPILER_MSC
#pragma warning(disable:4389) // '==' : signed/unsigned mismatch
#endif

View File

@ -14,7 +14,7 @@
#include <string>
#include <stdexcept>
#ifdef _MSC_VER
#ifdef CATCH_COMPILER_MSC
#pragma warning(disable:4702) // Unreachable code -- unconditional throws and so on
#endif
#ifdef CATCH_COMPILER_CLANG

View File

@ -41,7 +41,7 @@ namespace {
static bool alwaysTrue( int ) { return true; }
static bool alwaysFalse( int ) { return false; }
#ifdef _MSC_VER
#ifdef CATCH_COMPILER_MSC
# pragma warning( disable : 4702 ) // Unreachable code -- MSVC 19 (VS 2015)
// sees right through the indirection
#endif

View File

@ -221,7 +221,7 @@ TEST_CASE( "CAPTURE can deal with complex expressions", "[messages][capture]" )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-value" // All the comma operators are side-effect free
#endif
#ifdef _MSC_VER
#ifdef CATCH_COMPILER_MSC
#pragma warning(push)
#pragma warning(disable:4709) // comma in indexing operator
#endif
@ -283,6 +283,6 @@ TEST_CASE("CAPTURE parses string and character constants", "[messages][capture]"
#ifdef CATCH_COMPILER_GCC
#pragma GCC diagnostic pop
#endif
#ifdef _MSC_VER
#ifdef CATCH_COMPILER_MSC
#pragma warning(pop)
#endif

View File

@ -12,7 +12,7 @@
#pragma clang diagnostic ignored "-Wpadded"
#endif
#ifdef _MSC_VER
#ifdef CATCH_COMPILER_MSC
#pragma warning (disable : 4702) // Disable unreachable code warning for the last test
// that is triggered when compiling as Win32|Release
#endif

View File

@ -47,6 +47,8 @@
#include <sstream>
#include <vector>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#ifndef CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
#define CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH 80
#endif
@ -379,7 +381,7 @@ namespace clara { namespace TextFlow {
#include <set>
#include <algorithm>
#if !defined(CLARA_PLATFORM_WINDOWS) && ( defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) )
#if !defined(CLARA_PLATFORM_WINDOWS) && ( defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(CATCH_COMPILER_MSC) )
#define CLARA_PLATFORM_WINDOWS
#endif