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

Visual studio warnings fix
This commit is contained in:
Dominic Hamon 2015-10-08 10:06:01 -07:00
commit e2327733e6
11 changed files with 46 additions and 39 deletions

View File

@ -31,7 +31,12 @@ if (NOT HAVE_CXX_FLAG_STD_CXX11)
endif()
# 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(-Wshadow)
add_cxx_compiler_flag(-Werror RELEASE)

View File

@ -15,7 +15,7 @@
#include "benchmark/benchmark.h"
#include "internal_macros.h"
#ifndef OS_WINDOWS
#ifndef BENCHMARK_OS_WINDOWS
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
@ -623,7 +623,7 @@ void RunBenchmark(const benchmark::internal::Benchmark::Instance& b,
for (int i = 0; i < FLAGS_benchmark_repetitions; i++) {
std::string mem;
while (true) {
for (;;) {
// Try benchmark
VLOG(2) << "Running " << b.name << " for " << iters << "\n";

View File

@ -30,6 +30,9 @@ public:
std::abort();
}
CheckHandler & operator=(const CheckHandler&) = delete;
CheckHandler(const CheckHandler&) = delete;
CheckHandler() = delete;
private:
std::ostream& log_;
};

View File

@ -19,7 +19,7 @@
#include "commandlineflags.h"
#include "internal_macros.h"
#ifdef OS_WINDOWS
#ifdef BENCHMARK_OS_WINDOWS
#include <Windows.h>
#endif
@ -27,14 +27,14 @@ DECLARE_bool(color_print);
namespace benchmark {
namespace {
#ifdef OS_WINDOWS
#ifdef BENCHMARK_OS_WINDOWS
typedef WORD PlatformColorCode;
#else
typedef const char* PlatformColorCode;
#endif
PlatformColorCode GetPlatformColorCode(LogColor color) {
#ifdef OS_WINDOWS
#ifdef BENCHMARK_OS_WINDOWS
switch (color) {
case COLOR_RED:
return FOREGROUND_RED;
@ -85,7 +85,7 @@ void ColorPrintf(LogColor color, const char* fmt, ...) {
return;
}
#ifdef OS_WINDOWS
#ifdef BENCHMARK_OS_WINDOWS
const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
// Gets the current text color.

View File

@ -92,7 +92,7 @@ static std::string FlagToEnvVar(const char* flag) {
std::string env_var;
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;
}

View File

@ -41,7 +41,7 @@ extern "C" uint64_t __rdtsc();
#pragma intrinsic(__rdtsc)
#endif
#ifndef OS_WINDOWS
#ifndef BENCHMARK_OS_WINDOWS
#include <sys/time.h>
#endif

View File

@ -16,17 +16,17 @@
#endif
#if defined(__CYGWIN__)
# define OS_CYGWIN 1
# define BENCHMARK_OS_CYGWIN 1
#elif defined(_WIN32)
# define OS_WINDOWS 1
# define BENCHMARK_OS_WINDOWS 1
#elif defined(__APPLE__)
// TODO(ericwf) This doesn't actually check that it is a Mac OSX system. Just
// that it is an apple system.
# define OS_MACOSX 1
# define BENCHMARK_OS_MACOSX 1
#elif defined(__FreeBSD__)
# define OS_FREEBSD 1
# define BENCHMARK_OS_FREEBSD 1
#elif defined(__linux__)
# define OS_LINUX 1
# define BENCHMARK_OS_LINUX 1
#endif
#if defined(__clang__)

View File

@ -19,12 +19,12 @@
#include "internal_macros.h"
#ifdef OS_WINDOWS
#ifdef BENCHMARK_OS_WINDOWS
#include <Windows.h>
#endif
namespace benchmark {
#ifdef OS_WINDOWS
#ifdef BENCHMARK_OS_WINDOWS
// Window's Sleep takes milliseconds argument.
void SleepForMilliseconds(int milliseconds) { Sleep(milliseconds); }
void SleepForSeconds(double seconds) {

View File

@ -66,7 +66,7 @@ void ToExponentAndMantissa(double val, double thresh, int precision,
scaled *= one_k;
if (scaled >= small_threshold) {
mantissa_stream << scaled;
*exponent = -i - 1;
*exponent = -static_cast<int64_t>(i + 1);
*mantissa = mantissa_stream.str();
return;
}

View File

@ -15,9 +15,10 @@
#include "sysinfo.h"
#include "internal_macros.h"
#ifdef OS_WINDOWS
#ifdef BENCHMARK_OS_WINDOWS
#include <Shlwapi.h>
#include <Windows.h>
#include <VersionHelpers.h>
#else
#include <fcntl.h>
#include <sys/resource.h>
@ -51,7 +52,7 @@ double cpuinfo_cycles_per_second = 1.0;
int cpuinfo_num_cpus = 1; // Conservative guess
std::mutex cputimens_mutex;
#if !defined OS_MACOSX
#if !defined BENCHMARK_OS_MACOSX
const int64_t estimate_time_ms = 1000;
// Helper function estimates cycles/sec by observing cycles elapsed during
@ -63,7 +64,7 @@ int64_t EstimateCyclesPerSecond() {
}
#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
// and the memory location pointed to by value is set to the value read.
bool ReadIntFromFile(const char* file, long* value) {
@ -86,7 +87,7 @@ bool ReadIntFromFile(const char* file, long* value) {
#endif
void InitializeSystemInfo() {
#if defined OS_LINUX || defined OS_CYGWIN
#if defined BENCHMARK_OS_LINUX || defined BENCHMARK_OS_CYGWIN
char line[1024];
char* err;
long freq;
@ -204,7 +205,7 @@ void InitializeSystemInfo() {
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
// 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
@ -232,23 +233,21 @@ void InitializeSystemInfo() {
}
// 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
// then make a crude estimate.
OSVERSIONINFO os;
os.dwOSVersionInfoSize = sizeof(os);
DWORD data, data_size = sizeof(data);
if (GetVersionEx(&os) && os.dwPlatformId == VER_PLATFORM_WIN32_NT &&
if (IsWindowsXPOrGreater() &&
SUCCEEDED(
SHGetValueA(HKEY_LOCAL_MACHINE,
"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
"~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
cpuinfo_cycles_per_second = EstimateCyclesPerSecond();
cpuinfo_cycles_per_second = static_cast<double>(EstimateCyclesPerSecond());
// 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
// 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
@ -281,7 +280,7 @@ void InitializeSystemInfo() {
// getrusage() based implementation of MyCPUUsage
static double MyCPUUsageRUsage() {
#ifndef OS_WINDOWS
#ifndef BENCHMARK_OS_WINDOWS
struct rusage ru;
if (getrusage(RUSAGE_SELF, &ru) == 0) {
return (static_cast<double>(ru.ru_utime.tv_sec) +
@ -309,7 +308,7 @@ static double MyCPUUsageRUsage() {
#endif // OS_WINDOWS
}
#ifndef OS_WINDOWS
#ifndef BENCHMARK_OS_WINDOWS
static bool MyCPUUsageCPUTimeNsLocked(double* cputime) {
static int cputime_fd = -1;
if (cputime_fd == -1) {
@ -338,7 +337,7 @@ static bool MyCPUUsageCPUTimeNsLocked(double* cputime) {
#endif // OS_WINDOWS
double MyCPUUsage() {
#ifndef OS_WINDOWS
#ifndef BENCHMARK_OS_WINDOWS
{
std::lock_guard<std::mutex> l(cputimens_mutex);
static bool use_cputime_ns = true;
@ -357,7 +356,7 @@ double MyCPUUsage() {
}
double ChildrenCPUUsage() {
#ifndef OS_WINDOWS
#ifndef BENCHMARK_OS_WINDOWS
struct rusage ru;
if (getrusage(RUSAGE_CHILDREN, &ru) == 0) {
return (static_cast<double>(ru.ru_utime.tv_sec) +
@ -394,7 +393,7 @@ int NumCPUs(void) {
: nullptr)
bool CpuScalingEnabled() {
#ifndef OS_WINDOWS
#ifndef BENCHMARK_OS_WINDOWS
// 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
// running on Linux, so we silently ignore all the read errors.

View File

@ -16,7 +16,7 @@
#include "internal_macros.h"
#include "walltime.h"
#if defined(OS_WINDOWS)
#if defined(BENCHMARK_OS_WINDOWS)
#include <time.h>
#include <winsock.h> // for timeval
#else
@ -93,7 +93,7 @@ private:
WallTime Slow() const {
struct timeval tv;
#if defined(OS_WINDOWS)
#if defined(BENCHMARK_OS_WINDOWS)
FILETIME file_time;
SYSTEMTIME system_time;
ULARGE_INTEGER ularge;
@ -150,7 +150,7 @@ WallTime WallTimeImp::Now() {
// We are now sure that "now" and "result" were produced within
// kMaxErrorInterval of one another.
SetDrift(now - result);
SetDrift(static_cast<float>(now - result));
last_adjust_time_ = top_bits;
return now;
}
@ -231,7 +231,7 @@ std::string DateTimeString(bool local) {
std::size_t written;
if (local) {
#if defined(OS_WINDOWS)
#if defined(BENCHMARK_OS_WINDOWS)
written = std::strftime(storage, sizeof(storage), "%x %X", ::localtime(&now));
#else
std::tm timeinfo;
@ -240,7 +240,7 @@ std::string DateTimeString(bool local) {
written = std::strftime(storage, sizeof(storage), "%F %T", &timeinfo);
#endif
} else {
#if defined(OS_WINDOWS)
#if defined(BENCHMARK_OS_WINDOWS)
written = std::strftime(storage, sizeof(storage), "%x %X", ::gmtime(&now));
#else
std::tm timeinfo;