Fix SA for Visual Studio 16.8 (#8551)

I added `enum class` to one thing and decided that that was quite enough
before disabling the `enum class` warning.

Looks like 16.8 made more map/vector operations noexcept, so we have to
re-annotate to remain compliant.
This commit is contained in:
Dustin L. Howett 2020-12-10 21:04:30 -08:00 committed by GitHub
parent 4111be389d
commit eb2be374fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 43 additions and 40 deletions

View File

@ -11,6 +11,9 @@
<Rule Id="C26466" Action="None" />
<!-- This one has caught us off guard as it suddenly showed up. Re-enablement is going to be in #2941 -->
<Rule Id="C26814" Action="None" />
<!-- There are *so many* enums that should be enum classes. -->
<Rule Id="C26812" Action="None" />
</Rules>

View File

@ -21,12 +21,12 @@ AttrRowIterator::AttrRowIterator(const ATTR_ROW* const attrRow) noexcept :
{
}
AttrRowIterator::operator bool() const
AttrRowIterator::operator bool() const noexcept
{
return !_exceeded && _run < _pAttrRow->_list.cend();
}
bool AttrRowIterator::operator==(const AttrRowIterator& it) const
bool AttrRowIterator::operator==(const AttrRowIterator& it) const noexcept
{
return (_pAttrRow == it._pAttrRow &&
_run == it._run &&
@ -34,18 +34,18 @@ bool AttrRowIterator::operator==(const AttrRowIterator& it) const
_exceeded == it._exceeded);
}
bool AttrRowIterator::operator!=(const AttrRowIterator& it) const
bool AttrRowIterator::operator!=(const AttrRowIterator& it) const noexcept
{
return !(*this == it);
}
AttrRowIterator& AttrRowIterator::operator++()
AttrRowIterator& AttrRowIterator::operator++() noexcept
{
_increment(1);
return *this;
}
AttrRowIterator AttrRowIterator::operator++(int)
AttrRowIterator AttrRowIterator::operator++(int) noexcept
{
auto copy = *this;
_increment(1);
@ -74,13 +74,13 @@ AttrRowIterator& AttrRowIterator::operator-=(const ptrdiff_t& movement)
return this->operator+=(-movement);
}
AttrRowIterator& AttrRowIterator::operator--()
AttrRowIterator& AttrRowIterator::operator--() noexcept
{
_decrement(1);
return *this;
}
AttrRowIterator AttrRowIterator::operator--(int)
AttrRowIterator AttrRowIterator::operator--(int) noexcept
{
auto copy = *this;
_decrement(1);
@ -103,7 +103,7 @@ const TextAttribute& AttrRowIterator::operator*() const
// - increments the index the iterator points to
// Arguments:
// - count - the amount to increment by
void AttrRowIterator::_increment(size_t count)
void AttrRowIterator::_increment(size_t count) noexcept
{
while (count > 0)
{
@ -126,7 +126,7 @@ void AttrRowIterator::_increment(size_t count)
// - decrements the index the iterator points to
// Arguments:
// - count - the amount to decrement by
void AttrRowIterator::_decrement(size_t count)
void AttrRowIterator::_decrement(size_t count) noexcept
{
while (count > 0)
{

View File

@ -33,19 +33,19 @@ public:
AttrRowIterator(const ATTR_ROW* const attrRow) noexcept;
operator bool() const;
operator bool() const noexcept;
bool operator==(const AttrRowIterator& it) const;
bool operator!=(const AttrRowIterator& it) const;
bool operator==(const AttrRowIterator& it) const noexcept;
bool operator!=(const AttrRowIterator& it) const noexcept;
AttrRowIterator& operator++();
AttrRowIterator operator++(int);
AttrRowIterator& operator++() noexcept;
AttrRowIterator operator++(int) noexcept;
AttrRowIterator& operator+=(const ptrdiff_t& movement);
AttrRowIterator& operator-=(const ptrdiff_t& movement);
AttrRowIterator& operator--();
AttrRowIterator operator--(int);
AttrRowIterator& operator--() noexcept;
AttrRowIterator operator--(int) noexcept;
const TextAttribute* operator->() const;
const TextAttribute& operator*() const;
@ -56,7 +56,7 @@ private:
size_t _currentAttributeIndex; // index of TextAttribute within the current TextAttributeRun
bool _exceeded;
void _increment(size_t count);
void _decrement(size_t count);
void _increment(size_t count) noexcept;
void _decrement(size_t count) noexcept;
void _setToEnd() noexcept;
};

View File

@ -139,7 +139,7 @@ typename CharRow::const_iterator CharRow::cend() const noexcept
// - <none>
// Return Value:
// - The calculated left boundary of the internal string.
size_t CharRow::MeasureLeft() const
size_t CharRow::MeasureLeft() const noexcept
{
std::vector<value_type>::const_iterator it = _data.cbegin();
while (it != _data.cend() && it->IsSpace())

View File

@ -62,7 +62,7 @@ public:
size_t size() const noexcept;
void Reset() noexcept;
[[nodiscard]] HRESULT Resize(const size_t newSize) noexcept;
size_t MeasureLeft() const;
size_t MeasureLeft() const noexcept;
size_t MeasureRight() const noexcept;
void ClearCell(const size_t column);
bool ContainsText() const noexcept;

View File

@ -2322,7 +2322,7 @@ uint16_t TextBuffer::GetHyperlinkId(std::wstring_view uri, std::wstring_view id)
// user defined id from the custom id map (if there is one)
// Arguments:
// - The ID of the hyperlink to be removed
void TextBuffer::RemoveHyperlinkFromMap(uint16_t id)
void TextBuffer::RemoveHyperlinkFromMap(uint16_t id) noexcept
{
_hyperlinkMap.erase(id);
for (const auto& customIdPair : _hyperlinkCustomIdMap)

View File

@ -144,7 +144,7 @@ public:
void AddHyperlinkToMap(std::wstring_view uri, uint16_t id);
std::wstring GetHyperlinkUriFromId(uint16_t id) const;
uint16_t GetHyperlinkId(std::wstring_view uri, std::wstring_view id);
void RemoveHyperlinkFromMap(uint16_t id);
void RemoveHyperlinkFromMap(uint16_t id) noexcept;
std::wstring GetCustomIdFromId(uint16_t id) const;
void CopyHyperlinkMaps(const TextBuffer& OtherBuffer);

View File

@ -65,7 +65,7 @@ TextBufferCellIterator::operator bool() const noexcept
// - it - The other iterator to compare to this one.
// Return Value:
// - True if it's the same text buffer and same cell position. False otherwise.
bool TextBufferCellIterator::operator==(const TextBufferCellIterator& it) const
bool TextBufferCellIterator::operator==(const TextBufferCellIterator& it) const noexcept
{
return _pos == it._pos &&
&_buffer == &it._buffer &&
@ -81,7 +81,7 @@ bool TextBufferCellIterator::operator==(const TextBufferCellIterator& it) const
// - it - The other iterator to compare to this one.
// Return Value:
// - True if it's the same text buffer and different cell position or if they're different buffers. False otherwise.
bool TextBufferCellIterator::operator!=(const TextBufferCellIterator& it) const
bool TextBufferCellIterator::operator!=(const TextBufferCellIterator& it) const noexcept
{
return !(*this == it);
}

View File

@ -30,8 +30,8 @@ public:
operator bool() const noexcept;
bool operator==(const TextBufferCellIterator& it) const;
bool operator!=(const TextBufferCellIterator& it) const;
bool operator==(const TextBufferCellIterator& it) const noexcept;
bool operator!=(const TextBufferCellIterator& it) const noexcept;
TextBufferCellIterator& operator+=(const ptrdiff_t& movement);
TextBufferCellIterator& operator-=(const ptrdiff_t& movement);

View File

@ -84,7 +84,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
std::wstring cmdline{ wil::ExpandEnvironmentStringsW<std::wstring>(_commandline.c_str()) }; // mutable copy -- required for CreateProcessW
Utils::EnvironmentVariableMapW environment;
auto zeroEnvMap = wil::scope_exit([&] {
auto zeroEnvMap = wil::scope_exit([&]() noexcept {
// Can't zero the keys, but at least we can zero the values.
for (auto& [name, value] : environment)
{

View File

@ -1516,13 +1516,13 @@ try
// offset by half the stroke width. For the start coordinate we add half
// the stroke width, and for the end coordinate we subtract half the width.
if (lines & (GridLines::Left | GridLines::Right))
if (WI_IsAnyFlagSet(lines, (GridLines::Left | GridLines::Right)))
{
const auto halfGridlineWidth = _lineMetrics.gridlineWidth / 2.0f;
const auto startY = target.y + halfGridlineWidth;
const auto endY = target.y + font.height - halfGridlineWidth;
if (lines & GridLines::Left)
if (WI_IsFlagSet(lines, GridLines::Left))
{
auto x = target.x + halfGridlineWidth;
for (size_t i = 0; i < cchLine; i++, x += font.width)
@ -1531,7 +1531,7 @@ try
}
}
if (lines & GridLines::Right)
if (WI_IsFlagSet(lines, GridLines::Right))
{
auto x = target.x + font.width - halfGridlineWidth;
for (size_t i = 0; i < cchLine; i++, x += font.width)
@ -1541,19 +1541,19 @@ try
}
}
if (lines & (GridLines::Top | GridLines::Bottom))
if (WI_IsAnyFlagSet(lines, GridLines::Top | GridLines::Bottom))
{
const auto halfGridlineWidth = _lineMetrics.gridlineWidth / 2.0f;
const auto startX = target.x + halfGridlineWidth;
const auto endX = target.x + fullRunWidth - halfGridlineWidth;
if (lines & GridLines::Top)
if (WI_IsFlagSet(lines, GridLines::Top))
{
const auto y = target.y + halfGridlineWidth;
DrawLine(startX, y, endX, y, _lineMetrics.gridlineWidth);
}
if (lines & GridLines::Bottom)
if (WI_IsFlagSet(lines, GridLines::Bottom))
{
const auto y = target.y + font.height - halfGridlineWidth;
DrawLine(startX, y, endX, y, _lineMetrics.gridlineWidth);
@ -1563,24 +1563,24 @@ try
// In the case of the underline and strikethrough offsets, the stroke width
// is already accounted for, so they don't require further adjustments.
if (lines & (GridLines::Underline | GridLines::DoubleUnderline | GridLines::HyperlinkUnderline))
if (WI_IsAnyFlagSet(lines, GridLines::Underline | GridLines::DoubleUnderline | GridLines::HyperlinkUnderline))
{
const auto halfUnderlineWidth = _lineMetrics.underlineWidth / 2.0f;
const auto startX = target.x + halfUnderlineWidth;
const auto endX = target.x + fullRunWidth - halfUnderlineWidth;
const auto y = target.y + _lineMetrics.underlineOffset;
if (lines & GridLines::Underline)
if (WI_IsFlagSet(lines, GridLines::Underline))
{
DrawLine(startX, y, endX, y, _lineMetrics.underlineWidth);
}
if (lines & GridLines::HyperlinkUnderline)
if (WI_IsFlagSet(lines, GridLines::HyperlinkUnderline))
{
DrawHyperlinkLine(startX, y, endX, y, _lineMetrics.underlineWidth);
}
if (lines & GridLines::DoubleUnderline)
if (WI_IsFlagSet(lines, GridLines::DoubleUnderline))
{
DrawLine(startX, y, endX, y, _lineMetrics.underlineWidth);
const auto y2 = target.y + _lineMetrics.underlineOffset2;
@ -1588,7 +1588,7 @@ try
}
}
if (lines & GridLines::Strikethrough)
if (WI_IsFlagSet(lines, GridLines::Strikethrough))
{
const auto halfStrikethroughWidth = _lineMetrics.strikethroughWidth / 2.0f;
const auto startX = target.x + halfStrikethroughWidth;

View File

@ -72,7 +72,7 @@ void KeyEvent::ActivateModifierKey(const ModifierKeyState modifierKey) noexcept
SetActiveModifierKeys(keys);
}
bool KeyEvent::DoActiveModifierKeysMatch(const std::unordered_set<ModifierKeyState>& consoleModifiers) const
bool KeyEvent::DoActiveModifierKeysMatch(const std::unordered_set<ModifierKeyState>& consoleModifiers) const noexcept
{
DWORD consoleBits = 0;
for (const ModifierKeyState& mod : consoleModifiers)

View File

@ -297,7 +297,7 @@ public:
void SetActiveModifierKeys(const DWORD activeModifierKeys) noexcept;
void DeactivateModifierKey(const ModifierKeyState modifierKey) noexcept;
void ActivateModifierKey(const ModifierKeyState modifierKey) noexcept;
bool DoActiveModifierKeysMatch(const std::unordered_set<ModifierKeyState>& consoleModifiers) const;
bool DoActiveModifierKeysMatch(const std::unordered_set<ModifierKeyState>& consoleModifiers) const noexcept;
bool IsCommandLineEditingKey() const noexcept;
bool IsPopupKey() const noexcept;