Skip to content

Commit

Permalink
SERVER-17414 Enable Warnings As Errors on Windows, and disable/fix wa…
Browse files Browse the repository at this point in the history
…rnings
  • Loading branch information
markbenvenuto committed Oct 20, 2017
1 parent f13e5ad commit 98c383e
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 40 deletions.
4 changes: 4 additions & 0 deletions SConstruct
Expand Up @@ -1502,6 +1502,10 @@ elif env.TargetOSIs('windows'):
# object called lock on the stack.
env.Append( CCFLAGS=["/we4013", "/we4099", "/we4930"] )

# Warnings as errors
if not has_option("disable-warnings-as-errors"):
env.Append( CCFLAGS=["/WX"] )

env.Append( CPPDEFINES=["_CONSOLE","_CRT_SECURE_NO_WARNINGS", "_SCL_SECURE_NO_WARNINGS"] )

# this would be for pre-compiled headers, could play with it later
Expand Down
5 changes: 5 additions & 0 deletions src/mongo/base/parse_number.cpp
Expand Up @@ -173,7 +173,12 @@ Status parseNumberFromStringWithBase(StringData wholeString, int base, NumberTyp
if (magnitude > maxMagnitude)
return Status(ErrorCodes::FailedToParse, "Overflow");

#pragma warning(push)
// C4146: unary minus operator applied to unsigned type, result still unsigned
#pragma warning(disable : 4146)
*result = NumberType(isNegative ? -magnitude : magnitude);
#pragma warning(pop)

return Status::OK();
}

Expand Down
3 changes: 2 additions & 1 deletion src/mongo/bson/util/builder_test.cpp
Expand Up @@ -46,7 +46,8 @@ TEST(Builder, String1) {

TEST(Builder, StringBuilderAddress) {
const void* longPtr = reinterpret_cast<const void*>(-1);
const void* shortPtr = reinterpret_cast<const void*>(0xDEADBEEF);
const void* shortPtr = reinterpret_cast<const void*>(static_cast<uintptr_t>(0xDEADBEEF));

const void* nullPtr = NULL;

StringBuilder sb;
Expand Down
54 changes: 28 additions & 26 deletions src/mongo/db/fts/unicode/string_test.cpp
Expand Up @@ -42,6 +42,10 @@
#define UTF8(x) x
#endif

// Convert integer literals that are > 127 to unsigned char before converting to char
// to avoid MSVC C4309: truncation of constant value
#define C(x) static_cast<char>(static_cast<unsigned char>(x))

namespace mongo {
namespace unicode {

Expand Down Expand Up @@ -92,7 +96,7 @@ TEST(UnicodeString, RemoveDiacritics) {
const char test1[] = UTF8("¿CUÁNTOS AÑOS TIENES TÚ?");

// NFD Normalized Text ("Café").
const char test2[] = {'C', 'a', 'f', 'e', static_cast<char>(0xcc), static_cast<char>(0x81), 0};
const char test2[] = {'C', 'a', 'f', 'e', C(0xcc), C(0x81), 0};

TEST_CASE_FOLD_AND_STRIP_DIACRITICS(
UTF8("¿CUANTOS ANOS TIENES TU?"), test1, kCaseSensitive, kNormal);
Expand Down Expand Up @@ -146,7 +150,7 @@ TEST(UnicodeString, CaseFoldingAndRemoveDiacritics) {
const char test2[] = UTF8("¿CUÁNTOS AÑOS TIENES TÚ?");

// NFD Normalized Text ("CAFÉ").
const char test3[] = {'C', 'A', 'F', 'E', static_cast<char>(0xcc), static_cast<char>(0x81), 0};
const char test3[] = {'C', 'A', 'F', 'E', C(0xCc), C(0x81), 0};

TEST_CASE_FOLD_AND_STRIP_DIACRITICS(UTF8("ποσο χρονων εισαι?"), test1, 0, kNormal);
TEST_CASE_FOLD_AND_STRIP_DIACRITICS(UTF8("¿cuantos anos tienes tu?"), test2, 0, kNormal);
Expand Down Expand Up @@ -192,25 +196,23 @@ TEST(UnicodeString, SubstringMatchTurkish) {

TEST(UnicodeString, BadUTF8) {
// Overlong.
const char invalid1[] = {static_cast<char>(0xC0), static_cast<char>(0xAF), 0};
const char invalid1[] = {C(0xC0), C(0xAF), 0};

// Invalid code positions.
const char invalid2[] = {
static_cast<char>(0xED), static_cast<char>(0xA0), static_cast<char>(0x80), 0};
const char invalid3[] = {
static_cast<char>(0xC2), static_cast<char>(0x41), static_cast<char>(0x42), 0};
const char invalid2[] = {C(0xED), C(0xA0), C(0x80), 0};
const char invalid3[] = {C(0xC2), static_cast<char>(0x41), static_cast<char>(0x42), 0};
const char invalid4[] = {static_cast<char>(0x61),
static_cast<char>(0xF1),
static_cast<char>(0x80),
static_cast<char>(0x80),
static_cast<char>(0xE1),
static_cast<char>(0x80),
static_cast<char>(0xC2),
C(0xF1),
C(0x80),
C(0x80),
C(0xE1),
C(0x80),
C(0xC2),
static_cast<char>(0x62),
static_cast<char>(0x80),
C(0x80),
static_cast<char>(0x63),
static_cast<char>(0x80),
static_cast<char>(0xBF),
C(0x80),
C(0xBF),
static_cast<char>(0x64),
0};

Expand Down Expand Up @@ -240,16 +242,16 @@ TEST(UnicodeString, UTF32ToUTF8) {
original.push_back(0);

std::string expected_result;
expected_result.push_back(0x4D);
expected_result.push_back(0xD0);
expected_result.push_back(0xB0);
expected_result.push_back(0xE4);
expected_result.push_back(0xBA);
expected_result.push_back(0x8C);
expected_result.push_back(0xF0);
expected_result.push_back(0x90);
expected_result.push_back(0x8C);
expected_result.push_back(0x82);
expected_result.push_back(C(0x4D));
expected_result.push_back(C(0xD0));
expected_result.push_back(C(0xB0));
expected_result.push_back(C(0xE4));
expected_result.push_back(C(0xBA));
expected_result.push_back(C(0x8C));
expected_result.push_back(C(0xF0));
expected_result.push_back(C(0x90));
expected_result.push_back(C(0x8C));
expected_result.push_back(C(0x82));
expected_result.push_back(0);

std::string result(11, '\0');
Expand Down
4 changes: 4 additions & 0 deletions src/mongo/db/geo/hash.cpp
Expand Up @@ -847,7 +847,11 @@ double GeoHashConverter::sizeOfDiag(const GeoHash& a) const {
double GeoHashConverter::sizeEdge(unsigned level) const {
invariant(level >= 0);
invariant((int)level <= _params.bits);
#pragma warning(push)
// C4146: unary minus operator applied to unsigned type, result still unsigned
#pragma warning(disable : 4146)
return ldexp(_params.max - _params.min, -level);
#pragma warning(pop)
}

// Convert from a double in [0, (max-min)*scaling] to [min, max]
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/storage/kv/kv_catalog.cpp
Expand Up @@ -70,7 +70,7 @@ void appendPositionsOfBitsSet(uint64_t value, StringBuilder* sb) {
*sb << ", ";
}
*sb << lowestSetBitPosition;
value ^= (1 << lowestSetBitPosition);
value ^= (1ULL << lowestSetBitPosition);
firstIteration = false;
}
*sb << " ]";
Expand Down
4 changes: 4 additions & 0 deletions src/mongo/db/storage/mmap_v1/record_access_tracker_test.cpp
Expand Up @@ -40,7 +40,11 @@ namespace {
const std::unique_ptr<ClockSource> clock = stdx::make_unique<ClockSourceMock>();

const void* pointerOf(int data) {
#pragma warning(push)
// C4312: 'reinterpret_cast': conversion from 'int' to 'const void *' of greater size
#pragma warning(disable : 4312)
return reinterpret_cast<const void*>(data);
#pragma warning(pop)
}

TEST(RecordAccessTrackerTest, TouchRecordTwice) {
Expand Down
4 changes: 2 additions & 2 deletions src/mongo/dbtests/documentsourcetests.cpp
Expand Up @@ -314,7 +314,7 @@ TEST_F(DocumentSourceCursorTest, SerializationRespectsExplainModes) {
TEST_F(DocumentSourceCursorTest, TailableAwaitDataCursorStillUsableAfterTimeout) {
// Make sure the collection exists, otherwise we'll default to a NO_YIELD yield policy.
const bool capped = true;
const bool cappedSize = 1024;
const long long cappedSize = 1024;
ASSERT_TRUE(client.createCollection(nss.ns(), cappedSize, capped));
client.insert(nss.ns(), BSON("a" << 1));

Expand Down Expand Up @@ -392,7 +392,7 @@ TEST_F(DocumentSourceCursorTest, NonAwaitDataCursorShouldErrorAfterTimeout) {
TEST_F(DocumentSourceCursorTest, TailableAwaitDataCursorShouldErrorAfterBeingKilled) {
// Make sure the collection exists, otherwise we'll default to a NO_YIELD yield policy.
const bool capped = true;
const bool cappedSize = 1024;
const long long cappedSize = 1024;
ASSERT_TRUE(client.createCollection(nss.ns(), cappedSize, capped));
client.insert(nss.ns(), BSON("a" << 1));

Expand Down
9 changes: 7 additions & 2 deletions src/mongo/platform/decimal128.cpp
Expand Up @@ -776,8 +776,13 @@ namespace {
// Get the representation of 1 with 17 zeros (half of decimal128's 34 digit precision)
const std::uint64_t t17 = 100ull * 1000 * 1000 * 1000 * 1000 * 1000;
// Get the low 64 bits of 34 consecutive decimal 9's
// t17 * 17 gives 1 with 34 0's, so subtract 1 to get all 9's
const std::uint64_t t34lo64 = t17 * t17 - 1;
// t17 * 17 gives 1 with 34 0's, so subtract 1 to get all 9's == 4003012203950112767
// Using the computed constant avoids a MSVC warning.
// Computed by running the calculations in Python, and verified with static_assert.
const std::uint64_t t34lo64 = 4003012203950112767ULL;
#if defined(__GNUC__)
static_assert(t34lo64 == t17 * t17 - 1, "precomputed constant is wrong");
#endif
// Mod t17 by 2^32 to get the low 32 bits of t17's binary representation
const std::uint64_t t17lo32 = t17 % (1ull << 32);
// Divide t17 by 2^32 to get the high 32 bits of t17's binary representation
Expand Down
7 changes: 6 additions & 1 deletion src/mongo/util/exception_filter_win32.cpp
Expand Up @@ -32,7 +32,12 @@

#include "mongo/platform/basic.h"

#pragma warning(push)
// C4091: 'typedef ': ignored on left of '' when no variable is declared
#pragma warning(disable : 4091)
#include <DbgHelp.h>
#pragma warning(pop)

#include <ostream>

#include "mongo/config.h"
Expand Down Expand Up @@ -150,7 +155,7 @@ LONG WINAPI exceptionFilter(struct _EXCEPTION_POINTERS* excPointers) {
}
sprintf_s(addressString,
sizeof(addressString),
" 0x%p",
" 0x%llx",
excPointers->ExceptionRecord->ExceptionInformation[1]);
log() << "*** access violation was a " << acTypeString << addressString;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/util/net/sock.h
Expand Up @@ -250,7 +250,7 @@ class Socket {
/** raw recv, same semantics as ::recv */
int _recv(char* buf, int max);

int _fd;
SOCKET _fd;
uint64_t _fdCreationMicroSec;
SockAddr _local;
SockAddr _remote;
Expand Down
5 changes: 5 additions & 0 deletions src/mongo/util/processinfo_windows.cpp
Expand Up @@ -291,7 +291,12 @@ void ProcessInfo::SystemInfo::collectSystemInfo() {
// get OS version info
ZeroMemory(&osvi, sizeof(osvi));
osvi.dwOSVersionInfoSize = sizeof(osvi);
#pragma warning(push)
// GetVersionEx is deprecated
#pragma warning(disable : 4996)
if (GetVersionEx((OSVERSIONINFO*)&osvi)) {
#pragma warning(pop)

verstr << osvi.dwMajorVersion << "." << osvi.dwMinorVersion;
if (osvi.wServicePackMajor)
verstr << " SP" << osvi.wServicePackMajor;
Expand Down
9 changes: 5 additions & 4 deletions src/mongo/util/represent_as_test.cpp
Expand Up @@ -71,22 +71,23 @@ const double kInt32MinAsDouble = kInt32Min;
const uint32_t kUInt32Zero = 0;
const uint32_t kUInt32Max = std::numeric_limits<uint32_t>::max();
const int64_t kUInt32MaxAsInt64 = kUInt32Max;
const float kUInt32MaxAsFloat = kUInt32Max;
const float kUInt32MaxAsFloat = static_cast<float>(kUInt32Max);
const double kUInt32MaxAsDouble = kUInt32Max;

// 64-bit integer values
const int64_t kInt64Zero = 0;
const int64_t kInt64Max = std::numeric_limits<int64_t>::max();
const int64_t kInt64Min = std::numeric_limits<int64_t>::lowest();
const uint64_t kInt64MaxAsUInt64 = kInt64Max;
const double kInt64MaxAsDouble = kInt64Max;
const double kInt64MaxAsDouble = static_cast<double>(kInt64Max);
const double kInt64MinAsDouble = kInt64Min;

// Unsigned 64-bit integer values
const uint64_t kUInt64Zero = 0;
const uint64_t kUInt64Max = std::numeric_limits<uint64_t>::max();
const float kUInt64MaxAsFloat = kUInt64Max;
const double kUInt64MaxAsDouble = kUInt64Max;
const float kUInt64MaxAsFloat = static_cast<float>(kUInt64Max);
const double kUInt64MaxAsDouble = static_cast<double>(kUInt64Max);


// Long long values
const long long kLongLongMax = std::numeric_limits<long long>::max();
Expand Down
7 changes: 6 additions & 1 deletion src/mongo/util/stacktrace_windows.cpp
Expand Up @@ -31,7 +31,12 @@

#include "mongo/util/stacktrace.h"

#pragma warning(push)
// C4091: 'typedef ': ignored on left of '' when no variable is declared
#pragma warning(disable : 4091)
#include <DbgHelp.h>
#pragma warning(pop)

#include <boost/filesystem/operations.hpp>
#include <boost/optional.hpp>
#include <cstdio>
Expand Down Expand Up @@ -213,7 +218,7 @@ static void getsymbolAndOffset(HANDLE process,
std::string symbolString(symbolInfo->Name);
static const size_t bufferSize = 32;
std::unique_ptr<char[]> symbolOffset(new char[bufferSize]);
_snprintf(symbolOffset.get(), bufferSize, "+0x%x", displacement64);
_snprintf(symbolOffset.get(), bufferSize, "+0x%llux", displacement64);
symbolString += symbolOffset.get();
returnedSymbolAndOffset->swap(symbolString);
}
Expand Down
5 changes: 5 additions & 0 deletions src/mongo/util/summation_test.cpp
Expand Up @@ -67,7 +67,12 @@ std::vector<long long> longValues = {
1LL << 52,
1LL << 53,
limits::max() / 2,

#pragma warning(push)
// C4308: negative integral constant converted to unsigned type
#pragma warning(disable : 4308)
static_cast<long long>(1ULL << 63) - (1ULL << (63 - 53 - 1)), // Halfway between two doubles
#pragma warning(pop)
limits::max() - 1,
limits::max()};

Expand Down
6 changes: 6 additions & 0 deletions src/mongo/util/time_support_test.cpp
Expand Up @@ -50,13 +50,19 @@ char tzEnvString[] = "TZ=EST+5EDT";
#else
char tzEnvString[] = "TZ=America/New_York";
#endif

#pragma warning(push)
// C4996: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant
// name: _putenv. See online help for details.
#pragma warning(disable : 4996)
MONGO_INITIALIZER(SetTimeZoneToEasternForTest)(InitializerContext*) {
if (-1 == putenv(tzEnvString)) {
return Status(ErrorCodes::BadValue, errnoWithDescription());
}
tzset();
return Status::OK();
}
#pragma warning(pop)

TEST(TimeFormatting, DateAsISO8601UTCString) {
ASSERT_EQUALS(std::string("1970-01-01T00:00:00.000Z"), dateToISOStringUTC(Date_t()));
Expand Down
Expand Up @@ -173,7 +173,7 @@ namespace boost {
return (pos_type(off));
}
else {
BOOST_ASSERT(0); // 27.4.3.2 allows undefined-behaviour here
BOOST_ASSERT(0); // 27.4.3.2 allows undefined-behaviour here
return pos_type(off_type(-1));
}
}
Expand Down

0 comments on commit 98c383e

Please sign in to comment.