Build with /W4 (#197)

All projects are built with warning level 4 (/W4) and treat warnings as errors (/WX).
Fixed build errors resulting from enabling these compiler flags.
This commit is contained in:
Brett Waldbaum
2019-03-08 23:15:28 -08:00
committed by GitHub
parent e0f70e8c37
commit 64c6493312
30 changed files with 240 additions and 188 deletions

View File

@@ -154,6 +154,8 @@
<AdditionalIncludeDirectories>$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4453</DisableSpecificWarnings>
<AdditionalOptions>/bigobj /await /std:c++17 %(AdditionalOptions)</AdditionalOptions>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -172,6 +174,8 @@
<AdditionalIncludeDirectories>$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4453</DisableSpecificWarnings>
<AdditionalOptions>/bigobj /await /std:c++17 %(AdditionalOptions)</AdditionalOptions>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -190,6 +194,8 @@
<AdditionalIncludeDirectories>$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4453</DisableSpecificWarnings>
<AdditionalOptions>/bigobj /await /std:c++17 %(AdditionalOptions)</AdditionalOptions>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -208,6 +214,8 @@
<AdditionalIncludeDirectories>$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4453</DisableSpecificWarnings>
<AdditionalOptions>/bigobj /await /std:c++17 %(AdditionalOptions)</AdditionalOptions>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -226,6 +234,8 @@
<AdditionalIncludeDirectories>$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4453</DisableSpecificWarnings>
<AdditionalOptions>/bigobj /await /std:c++17 %(AdditionalOptions)</AdditionalOptions>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -244,6 +254,8 @@
<AdditionalIncludeDirectories>$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4453</DisableSpecificWarnings>
<AdditionalOptions>/bigobj /await /std:c++17 %(AdditionalOptions)</AdditionalOptions>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -262,6 +274,8 @@
<AdditionalIncludeDirectories>$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4453</DisableSpecificWarnings>
<AdditionalOptions>/bigobj /await /std:c++17 %(AdditionalOptions)</AdditionalOptions>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -280,6 +294,8 @@
<AdditionalIncludeDirectories>$(SolutionDir)..\src\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4453</DisableSpecificWarnings>
<AdditionalOptions>/bigobj /await /std:c++17 %(AdditionalOptions)</AdditionalOptions>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

View File

@@ -15,7 +15,6 @@ using namespace Windows::Foundation;
using namespace Windows::System;
using namespace Windows::ApplicationModel::DataTransfer;
size_t maxOperandLength;
unsigned long long maxOperandNumber;
String^ CopyPasteManager::supportedFormats[] =
@@ -533,7 +532,7 @@ size_t CopyPasteManager::ProgrammerOperandLength(const wstring& operand, int num
suffixes.insert(suffixes.end(), uintSuffixes.begin(), uintSuffixes.end());
wstring operandUpper = operand;
transform(operandUpper.begin(), operandUpper.end(), operandUpper.begin(), toupper);
transform(operandUpper.begin(), operandUpper.end(), operandUpper.begin(), towupper);
// Detect if there is a suffix and subtract its length
// Check suffixes first to allow e.g. "0b" to result in length 1 (value 0), rather than length 0 (no value).

View File

@@ -43,7 +43,6 @@ static multimap<int, multimap<MyVirtualKey, WeakReference>> s_VirtualKeyControlS
static multimap<int, multimap<MyVirtualKey, WeakReference>> s_VirtualKeyInverseChordsForButtons;
static multimap<int, multimap<MyVirtualKey, WeakReference>> s_VirtualKeyControlInverseChordsForButtons;
static const TimeSpan c_lightUpTime = { 500000 }; // Quarter of a second
static multimap<int, bool> s_ShiftKeyPressed;
static multimap<int, bool> s_ControlKeyPressed;
static multimap<int, bool> s_ShiftButtonChecked;
@@ -83,11 +82,13 @@ namespace CalculatorApp
// The button will go into the visual Pressed state with this call
VisualStateManager::GoToState(button, "Pressed", true);
// This timer will fire after c_lightUpTime and make the button
// This timer will fire after lightUpTime and make the button
// go back to the normal state.
// This timer will only fire once after which it will be destroyed
auto timer = ref new DispatcherTimer();
timer->Interval = c_lightUpTime;
TimeSpan lightUpTime{};
lightUpTime.Duration = 500000L; // Half second (in 100-ns units)
timer->Interval = lightUpTime;
WeakReference timerWeakReference(timer);
WeakReference buttonWeakReference(button);
@@ -579,9 +580,9 @@ void KeyboardShortcutManager::OnKeyDownHandler(CoreWindow^ sender, KeyEventArgs^
// Writer lock for the static maps
reader_writer_lock::scoped_lock lock(s_keyboardShortcutMapLock);
auto currentControlKeyPressed = s_ControlKeyPressed.find(viewId);
auto currControlKeyPressed = s_ControlKeyPressed.find(viewId);
if (currentControlKeyPressed != s_ControlKeyPressed.end())
if (currControlKeyPressed != s_ControlKeyPressed.end())
{
s_ControlKeyPressed.erase(viewId);
s_ControlKeyPressed.insert(std::make_pair(viewId, true));
@@ -593,9 +594,9 @@ void KeyboardShortcutManager::OnKeyDownHandler(CoreWindow^ sender, KeyEventArgs^
// Writer lock for the static maps
reader_writer_lock::scoped_lock lock(s_keyboardShortcutMapLock);
auto currentShiftKeyPressed = s_ShiftKeyPressed.find(viewId);
auto currShiftKeyPressed = s_ShiftKeyPressed.find(viewId);
if (currentShiftKeyPressed != s_ShiftKeyPressed.end())
if (currShiftKeyPressed != s_ShiftKeyPressed.end())
{
s_ShiftKeyPressed.erase(viewId);
s_ShiftKeyPressed.insert(std::make_pair(viewId, true));
@@ -636,7 +637,7 @@ void KeyboardShortcutManager::OnKeyUpHandler(CoreWindow^ sender, KeyEventArgs^ a
int viewId = Utils::GetWindowId();
auto key = args->VirtualKey;
if (args->VirtualKey == VirtualKey::Shift)
if (key == VirtualKey::Shift)
{
// Writer lock for the static maps
reader_writer_lock::scoped_lock lock(s_keyboardShortcutMapLock);
@@ -649,14 +650,14 @@ void KeyboardShortcutManager::OnKeyUpHandler(CoreWindow^ sender, KeyEventArgs^ a
s_ShiftKeyPressed.insert(std::make_pair(viewId, false));
}
}
else if (args->VirtualKey == VirtualKey::Control)
else if (key == VirtualKey::Control)
{
// Writer lock for the static maps
reader_writer_lock::scoped_lock lock(s_keyboardShortcutMapLock);
auto currentControlKeyPressed = s_ControlKeyPressed.find(viewId);
auto currControlKeyPressed = s_ControlKeyPressed.find(viewId);
if (currentControlKeyPressed != s_ControlKeyPressed.end())
if (currControlKeyPressed != s_ControlKeyPressed.end())
{
s_ControlKeyPressed.erase(viewId);
s_ControlKeyPressed.insert(std::make_pair(viewId, false));

View File

@@ -176,7 +176,7 @@ namespace CalculatorApp
{
iterMap->second.insert(iterMap->second.begin(), L"Programmer");
}
else
else if (isStandard)
{
iterMap->second.insert(iterMap->second.begin(), L"Standard");
}
@@ -199,7 +199,7 @@ namespace CalculatorApp
{
iterMap->second[memoryPosition] = L"Programmer";
}
else
else if (isStandard)
{
iterMap->second[memoryPosition] = L"Standard";
}
@@ -872,6 +872,7 @@ namespace CalculatorApp
if (!m_dateDiffUsageLoggedInSession)
{
LoggingFields fields{};
fields.AddUInt32(L"WindowId", windowId);
LogTelemetryEvent(EVENT_NAME_DATE_DIFFERENCE_USED, fields);
m_dateDiffUsageLoggedInSession = true;

View File

@@ -291,7 +291,6 @@ void HistoryViewModel::SaveHistory()
// this serializes a history item into a base64 encoded string
Platform::String^ HistoryViewModel::SerializeHistoryItem(_In_ std::shared_ptr<CalculationManager::HISTORYITEM> const &item)
{
HRESULT hr = S_OK;
DataWriter^ writer = ref new DataWriter();
auto expr = item->historyItemVector.expression;
auto result = item->historyItemVector.result;

View File

@@ -178,7 +178,6 @@ String^ StandardCalculatorViewModel::CalculateNarratorDisplayValue(_In_ wstring
String^ StandardCalculatorViewModel::GetNarratorStringReadRawNumbers(_In_ String^ localizedDisplayValue)
{
wstringstream wss;
RADIX_TYPE radix = static_cast<RADIX_TYPE>(CurrentRadixType);
auto& locSettings = LocalizationSettings::GetInstance();
// Insert a space after each digit in the string, to force Narrator to read them as separate numbers.
@@ -426,50 +425,50 @@ void StandardCalculatorViewModel::HandleUpdatedOperandData(Command cmdenum)
displayExpressionToken->CommandIndex = 0;
}
wchar_t ch;
wchar_t ch = 0;
if ((cmdenum >= Command::Command0) && (cmdenum <= Command::Command9))
{
switch (cmdenum)
{
case Command::Command0:
ch = '0';
ch = L'0';
break;
case Command::Command1:
ch = '1';
ch = L'1';
break;
case Command::Command2:
ch = '2';
ch = L'2';
break;
case Command::Command3:
ch = '3';
ch = L'3';
break;
case Command::Command4:
ch = '4';
ch = L'4';
break;
case Command::Command5:
ch = '5';
ch = L'5';
break;
case Command::Command6:
ch = '6';
ch = L'6';
break;
case Command::Command7:
ch = '7';
ch = L'7';
break;
case Command::Command8:
ch = '8';
ch = L'8';
break;
case Command::Command9:
ch = '9';
ch = L'9';
break;
}
}
else if (cmdenum == Command::CommandPNT)
{
ch = '.';
ch = L'.';
}
else if (cmdenum == Command::CommandBACK)
{
ch = 'x';
ch = L'x';
}
else
{
@@ -486,7 +485,7 @@ void StandardCalculatorViewModel::HandleUpdatedOperandData(Command cmdenum)
{
//Clear older text;
m_selectedExpressionLastData = L"";
if (ch == 'x')
if (ch == L'x')
{
temp[0] = L'\0';
commandIndex = 0;
@@ -501,7 +500,7 @@ void StandardCalculatorViewModel::HandleUpdatedOperandData(Command cmdenum)
}
else
{
if (ch == 'x')
if (ch == L'x')
{
if (commandIndex == 0)
{
@@ -518,7 +517,7 @@ void StandardCalculatorViewModel::HandleUpdatedOperandData(Command cmdenum)
}
temp[i++] = data[j];
}
temp[i] = '\0';
temp[i] = L'\0';
commandIndex -= 1;
}
else
@@ -537,7 +536,7 @@ void StandardCalculatorViewModel::HandleUpdatedOperandData(Command cmdenum)
}
temp[i] = data[j++];
}
temp[i] = '\0';
temp[i] = L'\0';
commandIndex += 1;
}
}
@@ -567,7 +566,6 @@ void StandardCalculatorViewModel::OnButtonPressed(Object^ parameter)
m_feedbackForButtonPress = CalculatorButtonPressedEventArgs::GetAuditoryFeedbackFromCommandParameter(parameter);
NumbersAndOperatorsEnum numOpEnum = CalculatorButtonPressedEventArgs::GetOperationFromCommandParameter(parameter);
Command cmdenum = ConvertToOperatorsEnum(numOpEnum);
bool isOperator = IsOperator(cmdenum);
TraceLogger::GetInstance().UpdateFunctionUsage((int)numOpEnum);
@@ -748,7 +746,6 @@ void StandardCalculatorViewModel::OnPaste(String^ pastedString, ViewMode mode)
bool isFirstLegalChar = true;
m_standardCalculatorManager.SendCommand(Command::CommandCENTR);
bool sendNegate = false;
bool processedExp = false;
bool processedDigit = false;
bool sentEquals = false;
bool isPreviousOperator = false;
@@ -1371,7 +1368,6 @@ ANGLE_TYPE GetAngleTypeFromCommand(Command command)
void StandardCalculatorViewModel::SaveEditedCommand(_In_ unsigned int tokenPosition, _In_ Command command)
{
pair<wstring, int> token;
bool fNegative = false;
bool handleOperand = false;
int nOpCode = static_cast<int>(command);
wstring updatedToken = L"";