Commit e2327733 by Dominic Hamon

Merge pull request #150 from DiracResearch/visual-studio-warnings-fix

Visual studio warnings fix
parents 406c2049 9195fd07
...@@ -31,7 +31,12 @@ if (NOT HAVE_CXX_FLAG_STD_CXX11) ...@@ -31,7 +31,12 @@ if (NOT HAVE_CXX_FLAG_STD_CXX11)
endif() endif()
# Turn compiler warnings up to 11 # Turn compiler warnings up to 11
add_cxx_compiler_flag(-Wall) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
add_cxx_compiler_flag(-W4)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
else()
add_cxx_compiler_flag(-Wall)
endif()
add_cxx_compiler_flag(-Wextra) add_cxx_compiler_flag(-Wextra)
add_cxx_compiler_flag(-Wshadow) add_cxx_compiler_flag(-Wshadow)
add_cxx_compiler_flag(-Werror RELEASE) add_cxx_compiler_flag(-Werror RELEASE)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "benchmark/benchmark.h" #include "benchmark/benchmark.h"
#include "internal_macros.h" #include "internal_macros.h"
#ifndef OS_WINDOWS #ifndef BENCHMARK_OS_WINDOWS
#include <sys/time.h> #include <sys/time.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <unistd.h> #include <unistd.h>
...@@ -623,7 +623,7 @@ void RunBenchmark(const benchmark::internal::Benchmark::Instance& b, ...@@ -623,7 +623,7 @@ void RunBenchmark(const benchmark::internal::Benchmark::Instance& b,
for (int i = 0; i < FLAGS_benchmark_repetitions; i++) { for (int i = 0; i < FLAGS_benchmark_repetitions; i++) {
std::string mem; std::string mem;
while (true) { for (;;) {
// Try benchmark // Try benchmark
VLOG(2) << "Running " << b.name << " for " << iters << "\n"; VLOG(2) << "Running " << b.name << " for " << iters << "\n";
......
...@@ -30,6 +30,9 @@ public: ...@@ -30,6 +30,9 @@ public:
std::abort(); std::abort();
} }
CheckHandler & operator=(const CheckHandler&) = delete;
CheckHandler(const CheckHandler&) = delete;
CheckHandler() = delete;
private: private:
std::ostream& log_; std::ostream& log_;
}; };
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "commandlineflags.h" #include "commandlineflags.h"
#include "internal_macros.h" #include "internal_macros.h"
#ifdef OS_WINDOWS #ifdef BENCHMARK_OS_WINDOWS
#include <Windows.h> #include <Windows.h>
#endif #endif
...@@ -27,14 +27,14 @@ DECLARE_bool(color_print); ...@@ -27,14 +27,14 @@ DECLARE_bool(color_print);
namespace benchmark { namespace benchmark {
namespace { namespace {
#ifdef OS_WINDOWS #ifdef BENCHMARK_OS_WINDOWS
typedef WORD PlatformColorCode; typedef WORD PlatformColorCode;
#else #else
typedef const char* PlatformColorCode; typedef const char* PlatformColorCode;
#endif #endif
PlatformColorCode GetPlatformColorCode(LogColor color) { PlatformColorCode GetPlatformColorCode(LogColor color) {
#ifdef OS_WINDOWS #ifdef BENCHMARK_OS_WINDOWS
switch (color) { switch (color) {
case COLOR_RED: case COLOR_RED:
return FOREGROUND_RED; return FOREGROUND_RED;
...@@ -85,7 +85,7 @@ void ColorPrintf(LogColor color, const char* fmt, ...) { ...@@ -85,7 +85,7 @@ void ColorPrintf(LogColor color, const char* fmt, ...) {
return; return;
} }
#ifdef OS_WINDOWS #ifdef BENCHMARK_OS_WINDOWS
const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
// Gets the current text color. // Gets the current text color.
......
...@@ -92,7 +92,7 @@ static std::string FlagToEnvVar(const char* flag) { ...@@ -92,7 +92,7 @@ static std::string FlagToEnvVar(const char* flag) {
std::string env_var; std::string env_var;
for (size_t i = 0; i != flag_str.length(); ++i) for (size_t i = 0; i != flag_str.length(); ++i)
env_var += ::toupper(flag_str.c_str()[i]); env_var += static_cast<char>(::toupper(flag_str.c_str()[i]));
return "BENCHMARK_" + env_var; return "BENCHMARK_" + env_var;
} }
......
...@@ -41,7 +41,7 @@ extern "C" uint64_t __rdtsc(); ...@@ -41,7 +41,7 @@ extern "C" uint64_t __rdtsc();
#pragma intrinsic(__rdtsc) #pragma intrinsic(__rdtsc)
#endif #endif
#ifndef OS_WINDOWS #ifndef BENCHMARK_OS_WINDOWS
#include <sys/time.h> #include <sys/time.h>
#endif #endif
......
...@@ -16,17 +16,17 @@ ...@@ -16,17 +16,17 @@
#endif #endif
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
# define OS_CYGWIN 1 # define BENCHMARK_OS_CYGWIN 1
#elif defined(_WIN32) #elif defined(_WIN32)
# define OS_WINDOWS 1 # define BENCHMARK_OS_WINDOWS 1
#elif defined(__APPLE__) #elif defined(__APPLE__)
// TODO(ericwf) This doesn't actually check that it is a Mac OSX system. Just // TODO(ericwf) This doesn't actually check that it is a Mac OSX system. Just
// that it is an apple system. // that it is an apple system.
# define OS_MACOSX 1 # define BENCHMARK_OS_MACOSX 1
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)
# define OS_FREEBSD 1 # define BENCHMARK_OS_FREEBSD 1
#elif defined(__linux__) #elif defined(__linux__)
# define OS_LINUX 1 # define BENCHMARK_OS_LINUX 1
#endif #endif
#if defined(__clang__) #if defined(__clang__)
......
...@@ -19,12 +19,12 @@ ...@@ -19,12 +19,12 @@
#include "internal_macros.h" #include "internal_macros.h"
#ifdef OS_WINDOWS #ifdef BENCHMARK_OS_WINDOWS
#include <Windows.h> #include <Windows.h>
#endif #endif
namespace benchmark { namespace benchmark {
#ifdef OS_WINDOWS #ifdef BENCHMARK_OS_WINDOWS
// Window's Sleep takes milliseconds argument. // Window's Sleep takes milliseconds argument.
void SleepForMilliseconds(int milliseconds) { Sleep(milliseconds); } void SleepForMilliseconds(int milliseconds) { Sleep(milliseconds); }
void SleepForSeconds(double seconds) { void SleepForSeconds(double seconds) {
......
...@@ -66,7 +66,7 @@ void ToExponentAndMantissa(double val, double thresh, int precision, ...@@ -66,7 +66,7 @@ void ToExponentAndMantissa(double val, double thresh, int precision,
scaled *= one_k; scaled *= one_k;
if (scaled >= small_threshold) { if (scaled >= small_threshold) {
mantissa_stream << scaled; mantissa_stream << scaled;
*exponent = -i - 1; *exponent = -static_cast<int64_t>(i + 1);
*mantissa = mantissa_stream.str(); *mantissa = mantissa_stream.str();
return; return;
} }
......
...@@ -15,9 +15,10 @@ ...@@ -15,9 +15,10 @@
#include "sysinfo.h" #include "sysinfo.h"
#include "internal_macros.h" #include "internal_macros.h"
#ifdef OS_WINDOWS #ifdef BENCHMARK_OS_WINDOWS
#include <Shlwapi.h> #include <Shlwapi.h>
#include <Windows.h> #include <Windows.h>
#include <VersionHelpers.h>
#else #else
#include <fcntl.h> #include <fcntl.h>
#include <sys/resource.h> #include <sys/resource.h>
...@@ -51,7 +52,7 @@ double cpuinfo_cycles_per_second = 1.0; ...@@ -51,7 +52,7 @@ double cpuinfo_cycles_per_second = 1.0;
int cpuinfo_num_cpus = 1; // Conservative guess int cpuinfo_num_cpus = 1; // Conservative guess
std::mutex cputimens_mutex; std::mutex cputimens_mutex;
#if !defined OS_MACOSX #if !defined BENCHMARK_OS_MACOSX
const int64_t estimate_time_ms = 1000; const int64_t estimate_time_ms = 1000;
// Helper function estimates cycles/sec by observing cycles elapsed during // Helper function estimates cycles/sec by observing cycles elapsed during
...@@ -63,7 +64,7 @@ int64_t EstimateCyclesPerSecond() { ...@@ -63,7 +64,7 @@ int64_t EstimateCyclesPerSecond() {
} }
#endif #endif
#if defined OS_LINUX || defined OS_CYGWIN #if defined BENCHMARK_OS_LINUX || defined BENCHMARK_OS_CYGWIN
// Helper function for reading an int from a file. Returns true if successful // Helper function for reading an int from a file. Returns true if successful
// and the memory location pointed to by value is set to the value read. // and the memory location pointed to by value is set to the value read.
bool ReadIntFromFile(const char* file, long* value) { bool ReadIntFromFile(const char* file, long* value) {
...@@ -86,7 +87,7 @@ bool ReadIntFromFile(const char* file, long* value) { ...@@ -86,7 +87,7 @@ bool ReadIntFromFile(const char* file, long* value) {
#endif #endif
void InitializeSystemInfo() { void InitializeSystemInfo() {
#if defined OS_LINUX || defined OS_CYGWIN #if defined BENCHMARK_OS_LINUX || defined BENCHMARK_OS_CYGWIN
char line[1024]; char line[1024];
char* err; char* err;
long freq; long freq;
...@@ -204,7 +205,7 @@ void InitializeSystemInfo() { ...@@ -204,7 +205,7 @@ void InitializeSystemInfo() {
cpuinfo_num_cpus = num_cpus; cpuinfo_num_cpus = num_cpus;
} }
#elif defined OS_FREEBSD #elif defined BENCHMARK_OS_FREEBSD
// For this sysctl to work, the machine must be configured without // For this sysctl to work, the machine must be configured without
// SMP, APIC, or APM support. hz should be 64-bit in freebsd 7.0 // SMP, APIC, or APM support. hz should be 64-bit in freebsd 7.0
// and later. Before that, it's a 32-bit quantity (and gives the // and later. Before that, it's a 32-bit quantity (and gives the
...@@ -232,23 +233,21 @@ void InitializeSystemInfo() { ...@@ -232,23 +233,21 @@ void InitializeSystemInfo() {
} }
// TODO: also figure out cpuinfo_num_cpus // TODO: also figure out cpuinfo_num_cpus
#elif defined OS_WINDOWS #elif defined BENCHMARK_OS_WINDOWS
// In NT, read MHz from the registry. If we fail to do so or we're in win9x // In NT, read MHz from the registry. If we fail to do so or we're in win9x
// then make a crude estimate. // then make a crude estimate.
OSVERSIONINFO os;
os.dwOSVersionInfoSize = sizeof(os);
DWORD data, data_size = sizeof(data); DWORD data, data_size = sizeof(data);
if (GetVersionEx(&os) && os.dwPlatformId == VER_PLATFORM_WIN32_NT && if (IsWindowsXPOrGreater() &&
SUCCEEDED( SUCCEEDED(
SHGetValueA(HKEY_LOCAL_MACHINE, SHGetValueA(HKEY_LOCAL_MACHINE,
"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
"~MHz", nullptr, &data, &data_size))) "~MHz", nullptr, &data, &data_size)))
cpuinfo_cycles_per_second = (int64_t)data * (int64_t)(1000 * 1000); // was mhz cpuinfo_cycles_per_second = static_cast<double>((int64_t)data * (int64_t)(1000 * 1000)); // was mhz
else else
cpuinfo_cycles_per_second = EstimateCyclesPerSecond(); cpuinfo_cycles_per_second = static_cast<double>(EstimateCyclesPerSecond());
// TODO: also figure out cpuinfo_num_cpus // TODO: also figure out cpuinfo_num_cpus
#elif defined OS_MACOSX #elif defined BENCHMARK_OS_MACOSX
// returning "mach time units" per second. the current number of elapsed // returning "mach time units" per second. the current number of elapsed
// mach time units can be found by calling uint64 mach_absolute_time(); // mach time units can be found by calling uint64 mach_absolute_time();
// while not as precise as actual CPU cycles, it is accurate in the face // while not as precise as actual CPU cycles, it is accurate in the face
...@@ -281,7 +280,7 @@ void InitializeSystemInfo() { ...@@ -281,7 +280,7 @@ void InitializeSystemInfo() {
// getrusage() based implementation of MyCPUUsage // getrusage() based implementation of MyCPUUsage
static double MyCPUUsageRUsage() { static double MyCPUUsageRUsage() {
#ifndef OS_WINDOWS #ifndef BENCHMARK_OS_WINDOWS
struct rusage ru; struct rusage ru;
if (getrusage(RUSAGE_SELF, &ru) == 0) { if (getrusage(RUSAGE_SELF, &ru) == 0) {
return (static_cast<double>(ru.ru_utime.tv_sec) + return (static_cast<double>(ru.ru_utime.tv_sec) +
...@@ -309,7 +308,7 @@ static double MyCPUUsageRUsage() { ...@@ -309,7 +308,7 @@ static double MyCPUUsageRUsage() {
#endif // OS_WINDOWS #endif // OS_WINDOWS
} }
#ifndef OS_WINDOWS #ifndef BENCHMARK_OS_WINDOWS
static bool MyCPUUsageCPUTimeNsLocked(double* cputime) { static bool MyCPUUsageCPUTimeNsLocked(double* cputime) {
static int cputime_fd = -1; static int cputime_fd = -1;
if (cputime_fd == -1) { if (cputime_fd == -1) {
...@@ -338,7 +337,7 @@ static bool MyCPUUsageCPUTimeNsLocked(double* cputime) { ...@@ -338,7 +337,7 @@ static bool MyCPUUsageCPUTimeNsLocked(double* cputime) {
#endif // OS_WINDOWS #endif // OS_WINDOWS
double MyCPUUsage() { double MyCPUUsage() {
#ifndef OS_WINDOWS #ifndef BENCHMARK_OS_WINDOWS
{ {
std::lock_guard<std::mutex> l(cputimens_mutex); std::lock_guard<std::mutex> l(cputimens_mutex);
static bool use_cputime_ns = true; static bool use_cputime_ns = true;
...@@ -357,7 +356,7 @@ double MyCPUUsage() { ...@@ -357,7 +356,7 @@ double MyCPUUsage() {
} }
double ChildrenCPUUsage() { double ChildrenCPUUsage() {
#ifndef OS_WINDOWS #ifndef BENCHMARK_OS_WINDOWS
struct rusage ru; struct rusage ru;
if (getrusage(RUSAGE_CHILDREN, &ru) == 0) { if (getrusage(RUSAGE_CHILDREN, &ru) == 0) {
return (static_cast<double>(ru.ru_utime.tv_sec) + return (static_cast<double>(ru.ru_utime.tv_sec) +
...@@ -394,7 +393,7 @@ int NumCPUs(void) { ...@@ -394,7 +393,7 @@ int NumCPUs(void) {
: nullptr) : nullptr)
bool CpuScalingEnabled() { bool CpuScalingEnabled() {
#ifndef OS_WINDOWS #ifndef BENCHMARK_OS_WINDOWS
// On Linux, the CPUfreq subsystem exposes CPU information as files on the // On Linux, the CPUfreq subsystem exposes CPU information as files on the
// local file system. If reading the exported files fails, then we may not be // local file system. If reading the exported files fails, then we may not be
// running on Linux, so we silently ignore all the read errors. // running on Linux, so we silently ignore all the read errors.
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "internal_macros.h" #include "internal_macros.h"
#include "walltime.h" #include "walltime.h"
#if defined(OS_WINDOWS) #if defined(BENCHMARK_OS_WINDOWS)
#include <time.h> #include <time.h>
#include <winsock.h> // for timeval #include <winsock.h> // for timeval
#else #else
...@@ -93,7 +93,7 @@ private: ...@@ -93,7 +93,7 @@ private:
WallTime Slow() const { WallTime Slow() const {
struct timeval tv; struct timeval tv;
#if defined(OS_WINDOWS) #if defined(BENCHMARK_OS_WINDOWS)
FILETIME file_time; FILETIME file_time;
SYSTEMTIME system_time; SYSTEMTIME system_time;
ULARGE_INTEGER ularge; ULARGE_INTEGER ularge;
...@@ -150,7 +150,7 @@ WallTime WallTimeImp::Now() { ...@@ -150,7 +150,7 @@ WallTime WallTimeImp::Now() {
// We are now sure that "now" and "result" were produced within // We are now sure that "now" and "result" were produced within
// kMaxErrorInterval of one another. // kMaxErrorInterval of one another.
SetDrift(now - result); SetDrift(static_cast<float>(now - result));
last_adjust_time_ = top_bits; last_adjust_time_ = top_bits;
return now; return now;
} }
...@@ -231,7 +231,7 @@ std::string DateTimeString(bool local) { ...@@ -231,7 +231,7 @@ std::string DateTimeString(bool local) {
std::size_t written; std::size_t written;
if (local) { if (local) {
#if defined(OS_WINDOWS) #if defined(BENCHMARK_OS_WINDOWS)
written = std::strftime(storage, sizeof(storage), "%x %X", ::localtime(&now)); written = std::strftime(storage, sizeof(storage), "%x %X", ::localtime(&now));
#else #else
std::tm timeinfo; std::tm timeinfo;
...@@ -240,7 +240,7 @@ std::string DateTimeString(bool local) { ...@@ -240,7 +240,7 @@ std::string DateTimeString(bool local) {
written = std::strftime(storage, sizeof(storage), "%F %T", &timeinfo); written = std::strftime(storage, sizeof(storage), "%F %T", &timeinfo);
#endif #endif
} else { } else {
#if defined(OS_WINDOWS) #if defined(BENCHMARK_OS_WINDOWS)
written = std::strftime(storage, sizeof(storage), "%x %X", ::gmtime(&now)); written = std::strftime(storage, sizeof(storage), "%x %X", ::gmtime(&now));
#else #else
std::tm timeinfo; std::tm timeinfo;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment