Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add const keyword to resolve warnings (treated as errors) C26462 and C26496 #8567

Merged
merged 5 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/AutoSuggestBox/AutoSuggestBoxHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void AutoSuggestBoxHelper::OnKeepInteriorCornersSquarePropertyChanged(
{
if (auto autoSuggestBox = sender.try_as<winrt::AutoSuggestBox>())
{
bool shouldMonitorAutoSuggestEvents = unbox_value<bool>(args.NewValue());
const bool shouldMonitorAutoSuggestEvents = unbox_value<bool>(args.NewValue());
if (shouldMonitorAutoSuggestEvents)
{
auto revokersInspectable = winrt::make<AutoSuggestEventRevokers>();
Expand Down
2 changes: 1 addition & 1 deletion dev/Breadcrumb/BreadcrumbBarItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ bool BreadcrumbBarItem::IgnorePointerId(const winrt::PointerRoutedEventArgs& arg
{
MUX_ASSERT(m_isEllipsisDropDownItem);

uint32_t pointerId = args.Pointer().PointerId();
const uint32_t pointerId = args.Pointer().PointerId();

if (m_trackedPointerId == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion dev/Breadcrumb/BreadcrumbLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int BreadcrumbLayout::GetFirstBreadcrumbBarItemToArrange(winrt::NonVirtualizingL

for (int i = itemCount - 2; i >= 0; --i)
{
float newAccumLength = accumLength + GetElementAt(context, i).DesiredSize().Width;
const float newAccumLength = accumLength + GetElementAt(context, i).DesiredSize().Width;
if (newAccumLength > m_availableSize.Width)
{
return i + 1;
Expand Down
4 changes: 2 additions & 2 deletions dev/ColorPicker/ColorPicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ void ColorPicker::OnColorChanged(winrt::DependencyPropertyChangedEventArgs const
UpdateColorControls(ColorUpdateReason::ColorPropertyChanged);
}

winrt::Color oldColor = unbox_value<winrt::Color>(args.OldValue());
winrt::Color newColor = unbox_value<winrt::Color>(args.NewValue());
const winrt::Color oldColor = unbox_value<winrt::Color>(args.OldValue());
const winrt::Color newColor = unbox_value<winrt::Color>(args.NewValue());

if (oldColor.A != newColor.A ||
oldColor.R != newColor.R ||
Expand Down
2 changes: 1 addition & 1 deletion dev/ColorPicker/ColorPickerSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void ColorPickerSlider::OnKeyDown(winrt::KeyRoutedEventArgs const& args)
return;
}

bool isControlDown = (winrt::Window::Current().CoreWindow().GetKeyState(winrt::VirtualKey::Control) & winrt::CoreVirtualKeyStates::Down) == winrt::CoreVirtualKeyStates::Down;
const bool isControlDown = (winrt::Window::Current().CoreWindow().GetKeyState(winrt::VirtualKey::Control) & winrt::CoreVirtualKeyStates::Down) == winrt::CoreVirtualKeyStates::Down;

double minBound = 0;
double maxBound = 0;
Expand Down
2 changes: 1 addition & 1 deletion dev/ComboBox/ComboBoxHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void ComboBoxHelper::OnKeepInteriorCornersSquarePropertyChanged(
{
if (auto comboBox = sender.try_as<winrt::ComboBox>())
{
bool shouldMonitorDropDownState = unbox_value<bool>(args.NewValue());
const bool shouldMonitorDropDownState = unbox_value<bool>(args.NewValue());
if (shouldMonitorDropDownState)
{
auto revokersInspectable = winrt::make<ComboBoxDropDownEventRevokers>();
Expand Down
4 changes: 2 additions & 2 deletions dev/CommandBarFlyout/CommandBarFlyoutCommandBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ void CommandBarFlyoutCommandBar::UpdateVisualState(

// If there isn't enough space to display the overflow below the command bar,
// and if there is enough space above, then we'll display it above instead.
if (auto window = winrt::Window::Current() && !hadActualPlacement && m_secondaryItemsRoot)
if (const auto window = winrt::Window::Current() && !hadActualPlacement && m_secondaryItemsRoot)
{
double availableHeight = -1;
const auto controlBounds = TransformToVisual(nullptr).TransformBounds({ 0, 0, static_cast<float>(ActualWidth()), static_cast<float>(ActualHeight()) });
Expand Down Expand Up @@ -595,7 +595,7 @@ void CommandBarFlyoutCommandBar::UpdateVisualState(
winrt::VisualStateManager::GoToState(*this, shouldExpandUp ? L"ExpandedUp" : L"ExpandedDown", useTransitions && !isForSizeChange);

// Union of AvailableCommandsStates and ExpansionStates
bool hasPrimaryCommands = (PrimaryCommands().Size() != 0);
const bool hasPrimaryCommands = (PrimaryCommands().Size() != 0);
if (hasPrimaryCommands)
{
if (shouldExpandUp)
Expand Down
6 changes: 3 additions & 3 deletions dev/CommandBarFlyout/TextCommandBarFlyout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void TextCommandBarFlyout::UpdateButtons()

winrt::MenuFlyout proofingMenuFlyout = proofingFlyout.try_as<winrt::MenuFlyout>();

bool shouldIncludeProofingMenu =
const bool shouldIncludeProofingMenu =
static_cast<bool>(proofingFlyout) &&
(!proofingMenuFlyout || proofingMenuFlyout.Items().Size() > 0);

Expand Down Expand Up @@ -323,7 +323,7 @@ void TextCommandBarFlyout::UpdateButtons()
addRichEditButtonToCommandsIfPresent(TextControlButtons::Underline, PrimaryCommands(),
[](winrt::ITextSelection textSelection)
{
auto underline = textSelection.CharacterFormat().Underline();
const auto underline = textSelection.CharacterFormat().Underline();
return (underline != winrt::UnderlineType::None) && (underline != winrt::UnderlineType::Undefined);
});

Expand Down Expand Up @@ -554,7 +554,7 @@ TextControlButtons TextCommandBarFlyout::GetPasswordBoxButtonsToAdd(winrt::Passw
bool TextCommandBarFlyout::IsButtonInPrimaryCommands(TextControlButtons button)
{
uint32_t buttonIndex = 0;
bool wasFound = PrimaryCommands().IndexOf(GetButton(button), buttonIndex);
const bool wasFound = PrimaryCommands().IndexOf(GetButton(button), buttonIndex);
return wasFound;
}

Expand Down
2 changes: 1 addition & 1 deletion dev/InfoBar/InfoBarPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ winrt::Size InfoBarPanel::ArrangeOverride(winrt::Size const& finalSize)
auto const desiredSize = child.DesiredSize();
if (desiredSize.Width != 0 && desiredSize.Height != 0)
{
auto horizontalMargin = winrt::InfoBarPanel::GetHorizontalOrientationMargin(child);
const auto horizontalMargin = winrt::InfoBarPanel::GetHorizontalOrientationMargin(child);

horizontalOffset += hasPreviousElement ? (float)horizontalMargin.Left : 0;
if (i < childCount - 1)
Expand Down
2 changes: 1 addition & 1 deletion dev/Materials/Backdrop/SystemBackdropWindowHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ namespace SystemBackdropComponentInternal
else if (retryOnNextTick && !m_nextTickRevoker)
{
// We don't have a root yet so let's start with the system theme as the best we can do until the content appears.
auto systemTheme = winrt::Application::Current().RequestedTheme();
const auto systemTheme = winrt::Application::Current().RequestedTheme();
m_actualTheme = (systemTheme == winrt::ApplicationTheme::Dark) ? winrt::ElementTheme::Dark : winrt::ElementTheme::Light;
m_controller->UpdateTheme(m_actualTheme);

Expand Down
8 changes: 4 additions & 4 deletions dev/Materials/Reveal/RevealBrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ winrt::Windows::Graphics::Effects::IGraphicsEffect RevealBrush::CreateRevealHove
// </CompositeStepEffect>
// </ColorMatrixEffect>
// </ArithmeticCompositeEffect>
winrt::Color initBaseColor{ 0, 0, 0, 0 };
const winrt::Color initBaseColor{ 0, 0, 0, 0 };

// (9) Noise image BorderEffect (infinitely tiles noise image)
auto noiseBorderEffect = winrt::make_self<Microsoft::UI::Private::Composition::Effects::BorderEffect>();
Expand Down Expand Up @@ -881,8 +881,8 @@ bool RevealBrush::ValidatePublicRootAncestor()
// Either Window.Content is a Canvas, in which case it's the immediate child of the root visual and we should set lights
// on it directly, or it isn't, in which case we should have walked up to the RootScrollViewer and set lights there.
auto ancestor = GetAncestor(windowRoot);
bool windowContentIsCanvas = static_cast<bool>(windowRoot.try_as<winrt::Canvas>());
bool walkedUpToScrollViewer = winrt::VisualTreeHelper::GetParent(windowRoot) &&
const bool windowContentIsCanvas = static_cast<bool>(windowRoot.try_as<winrt::Canvas>());
const bool walkedUpToScrollViewer = winrt::VisualTreeHelper::GetParent(windowRoot) &&
static_cast<bool>(ancestor.try_as<winrt::FxScrollViewer>());

// On MUX + RS3/RS4, it's possible XCB::OnConnected is called before visual tree is constructed and the ancestor walk returns a false elemenet.
Expand Down Expand Up @@ -1054,7 +1054,7 @@ void RevealBrush::OnIsContainerPropertyChanged(
{
if (auto elementSender = sender.try_as<winrt::IUIElement5>())
{
bool isAdding = unbox_value<bool>(args.NewValue());
const bool isAdding = unbox_value<bool>(args.NewValue());

auto lights = elementSender.Lights();
int i = 0;
Expand Down
12 changes: 6 additions & 6 deletions dev/NavigationView/NavigationView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ void NavigationView::RaiseItemInvokedForNavigationViewItem(const winrt::Navigati
if (auto itemsSourceView = parentIR.ItemsSourceView())
{
auto inspectingDataSource = static_cast<InspectingDataSource*>(winrt::get_self<ItemsSourceView>(itemsSourceView));
auto itemIndex = parentIR.GetElementIndex(nvi);
const auto itemIndex = parentIR.GetElementIndex(nvi);

// Check that index is NOT -1, meaning it is actually realized
if (itemIndex != -1)
Expand All @@ -1005,7 +1005,7 @@ void NavigationView::RaiseItemInvokedForNavigationViewItem(const winrt::Navigati

// Determine the recommeded transition direction.
// Any transitions other than `Default` only apply in top nav scenarios.
auto recommendedDirection = [this, prevItem, nvi, parentIR]()
const auto recommendedDirection = [this, prevItem, nvi, parentIR]()
{
if (IsTopNavigationView() && nvi.SelectsOnInvoked())
{
Expand Down Expand Up @@ -1209,7 +1209,7 @@ void NavigationView::OnRepeaterElementPrepared(const winrt::ItemsRepeater& ir, c
nvibImpl->IsTopLevelItem(IsTopLevelItem(nvib));

// Visual state info propagation
auto position = [this, ir]()
const auto position = [this, ir]()
{
if (IsTopNavigationView())
{
Expand Down Expand Up @@ -2350,7 +2350,7 @@ void NavigationView::ChangeSelection(const winrt::IInspectable& prevItem, const
// otherwise if prevItem is on left side of nextActualItem, transition is from left
// if prevItem is on right side of nextActualItem, transition is from right
// click on Settings item is considered Default
auto recommendedDirection = [this, prevItem, nextItem]()
const auto recommendedDirection = [this, prevItem, nextItem]()
{
if (IsTopNavigationView())
{
Expand Down Expand Up @@ -2943,7 +2943,7 @@ void NavigationView::OnKeyDown(winrt::KeyRoutedEventArgs const& e)
m_TabKeyPrecedesFocusChange = true;
break;
case winrt::VirtualKey::Left:
auto altState = winrt::CoreWindow::GetForCurrentThread().GetKeyState(winrt::VirtualKey::Menu);
const auto altState = winrt::CoreWindow::GetForCurrentThread().GetKeyState(winrt::VirtualKey::Menu);
const bool isAltPressed = (altState & winrt::CoreVirtualKeyStates::Down) == winrt::CoreVirtualKeyStates::Down;

if (isAltPressed && IsPaneOpen() && IsLightDismissible())
Expand Down Expand Up @@ -4936,7 +4936,7 @@ void NavigationView::UpdatePaneShadow()

// Shadow will get clipped if casting on the splitView.Content directly
// Creating a canvas with negative margins as receiver to allow shadow to be drawn outside the content grid
winrt::Thickness shadowReceiverMargin = { 0, -c_paneElevationTranslationZ, -c_paneElevationTranslationZ, -c_paneElevationTranslationZ };
const winrt::Thickness shadowReceiverMargin = { 0, -c_paneElevationTranslationZ, -c_paneElevationTranslationZ, -c_paneElevationTranslationZ };

// Ensuring shadow is aligned to the left
shadowReceiver.HorizontalAlignment(winrt::HorizontalAlignment::Left);
Expand Down
4 changes: 2 additions & 2 deletions dev/NavigationView/NavigationViewItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ void NavigationViewItem::PropagateDepthToChildren(int depth)
{
if (auto const repeater = m_repeater.get())
{
auto itemsCount = repeater.ItemsSourceView().Count();
const auto itemsCount = repeater.ItemsSourceView().Count();
for (int index = 0; index < itemsCount; index++)
{
if (auto const element = repeater.TryGetElement(index))
Expand Down Expand Up @@ -934,7 +934,7 @@ void NavigationViewItem::ResetTrackedPointerId()
// Returns True when the provided pointer Id does not match the currently tracked Id.
bool NavigationViewItem::IgnorePointerId(const winrt::PointerRoutedEventArgs& args)
{
uint32_t pointerId = args.Pointer().PointerId();
const uint32_t pointerId = args.Pointer().PointerId();

if (m_trackedPointerId == 0)
{
Expand Down
10 changes: 5 additions & 5 deletions dev/ParallaxView/ScrollInputHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void ScrollInputHelper::UpdateContentSize()
return;
}

int childrenCount = winrt::VisualTreeHelper::GetChildrenCount(itemsPresenter);
const int childrenCount = winrt::VisualTreeHelper::GetChildrenCount(itemsPresenter);

if (childrenCount > 0)
{
Expand Down Expand Up @@ -474,7 +474,7 @@ void ScrollInputHelper::UpdateViewportSize()

if (itemsPresenter)
{
int childrenCount = winrt::VisualTreeHelper::GetChildrenCount(itemsPresenter);
const int childrenCount = winrt::VisualTreeHelper::GetChildrenCount(itemsPresenter);

if (childrenCount > 0)
{
Expand Down Expand Up @@ -580,8 +580,8 @@ void ScrollInputHelper::UpdateIsTargetElementInSource()

if (targetElement)
{
bool sourceIsScrollViewer = m_scrollViewer != nullptr;
bool sourceIsScrollPresenter = m_scrollPresenter != nullptr;
const bool sourceIsScrollViewer = m_scrollViewer != nullptr;
const bool sourceIsScrollPresenter = m_scrollPresenter != nullptr;

if (sourceIsScrollViewer || sourceIsScrollPresenter)
{
Expand Down Expand Up @@ -820,7 +820,7 @@ bool ScrollInputHelper::IsScrollContentPresenterIScrollInfoProvider() const

if (itemsPresenter)
{
int childrenCount = winrt::VisualTreeHelper::GetChildrenCount(itemsPresenter);
const int childrenCount = winrt::VisualTreeHelper::GetChildrenCount(itemsPresenter);

if (childrenCount > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion dev/PersonPicture/InitialsGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ winrt::hstring InitialsGenerator::InitialsFromContactObject(const winrt::Contact
// available, that is the data which should be used.
if (!contact.FirstName().empty() && !contact.LastName().empty())
{
CharacterType type = GetCharacterType(contact.FirstName());
const CharacterType type = GetCharacterType(contact.FirstName());

// We'll attempt to make initials only if we recognize a name in the Standard character set.
if (type == CharacterType::Standard)
Expand Down
10 changes: 5 additions & 5 deletions dev/RatingControl/RatingControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void RatingControl::UpdateCaptionMargins()
// When text scale changes we need to update top margin to make the text follow start center.
if (auto captionTextBlock = m_captionTextBlock.safe_get())
{
double textScaleFactor = GetUISettings().TextScaleFactor();
const double textScaleFactor = GetUISettings().TextScaleFactor();
winrt::Thickness margin = captionTextBlock.Margin();
margin.Top = c_defaultCaptionTopMargin - (ActualRatingFontSize() * c_verticalScaleAnimationCenterPoint);

Expand Down Expand Up @@ -767,7 +767,7 @@ void RatingControl::OnPointerMovedOverBackgroundStackPanel(const winrt::IInspect
if (ShouldEnableAnimation())
{
m_sharedPointerPropertySet.InsertScalar(L"starsScaleFocalPoint", xPosition);
auto deviceType = args.Pointer().PointerDeviceType();
const auto deviceType = args.Pointer().PointerDeviceType();

switch (deviceType)
{
Expand Down Expand Up @@ -914,7 +914,7 @@ void RatingControl::OnKeyDown(winrt::KeyRoutedEventArgs const& eventArgs)
flowDirectionReverser *= -1.0;
}

auto originalKey = eventArgs.as<winrt::KeyRoutedEventArgs>().OriginalKey();
const auto originalKey = eventArgs.as<winrt::KeyRoutedEventArgs>().OriginalKey();

// Up down are right/left in keyboard only
if (originalKey == winrt::VirtualKey::Up)
Expand Down Expand Up @@ -989,7 +989,7 @@ void RatingControl::OnPreviewKeyDown(winrt::KeyRoutedEventArgs const& eventArgs)

if (!IsReadOnly() && IsFocusEngaged() && IsFocusEngagementEnabled())
{
auto originalKey = eventArgs.as<winrt::KeyRoutedEventArgs>().OriginalKey();
const auto originalKey = eventArgs.as<winrt::KeyRoutedEventArgs>().OriginalKey();
if (originalKey == winrt::VirtualKey::GamepadA)
{
m_shouldDiscardValue = false;
Expand Down Expand Up @@ -1024,7 +1024,7 @@ void RatingControl::OnPreviewKeyDown(winrt::KeyRoutedEventArgs const& eventArgs)

void RatingControl::OnPreviewKeyUp(winrt::KeyRoutedEventArgs const& eventArgs)
{
auto originalKey = eventArgs.as<winrt::KeyRoutedEventArgs>().OriginalKey();
const auto originalKey = eventArgs.as<winrt::KeyRoutedEventArgs>().OriginalKey();

if (IsFocusEngagementEnabled() && originalKey == winrt::VirtualKey::GamepadA && m_disengagedWithA)
{
Expand Down
10 changes: 5 additions & 5 deletions dev/RatingControl/RatingControlAutomationPeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ bool RatingControlAutomationPeer::IsReadOnly()

hstring RatingControlAutomationPeer::IValueProvider_Value()
{
double ratingValue = GetRatingControl().Value();
const double ratingValue = GetRatingControl().Value();
winrt::hstring valueString;

winrt::hstring ratingString;

if (ratingValue == -1)
{
double placeholderValue = GetRatingControl().PlaceholderValue();
const double placeholderValue = GetRatingControl().PlaceholderValue();
if (placeholderValue == -1)
{
valueString = ResourceAccessor::GetLocalizedStringResource(SR_RatingUnset);
Expand Down Expand Up @@ -86,7 +86,7 @@ double RatingControlAutomationPeer::Minimum()
double RatingControlAutomationPeer::Value()
{
// Change this to provide a placeholder value too.
double value = GetRatingControl().Value();
const double value = GetRatingControl().Value();
if (value == -1)
{
return 0;
Expand Down Expand Up @@ -123,12 +123,12 @@ winrt::AutomationControlType RatingControlAutomationPeer::GetAutomationControlTy
void RatingControlAutomationPeer::RaisePropertyChangedEvent(double newValue)
{
// UIA doesn't tolerate a null doubles, so we convert them to zeroes.
double oldValue = GetRatingControl().Value();
const double oldValue = GetRatingControl().Value();
auto oldValueProp = winrt::PropertyValue::CreateDouble(oldValue);

if (newValue == -1)
{
auto newValueProp = winrt::PropertyValue::CreateDouble(0.0);
const auto newValueProp = winrt::PropertyValue::CreateDouble(0.0);
__super::RaisePropertyChangedEvent(winrt::ValuePatternIdentifiers::ValueProperty(), oldValueProp, newValueProp);
__super::RaisePropertyChangedEvent(winrt::RangeValuePatternIdentifiers::ValueProperty(), oldValueProp, newValueProp);
}
Expand Down
2 changes: 1 addition & 1 deletion dev/Repeater/ElementManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void ElementManager::DataSourceChanged(const winrt::IInspectable& /*source*/, wi
break;

case winrt::NotifyCollectionChangedAction::Move:
int size = args.OldItems() != NULL ? args.OldItems().Size() : 1;
const int size = args.OldItems() != NULL ? args.OldItems().Size() : 1;
OnItemsRemoved(args.OldStartingIndex(), size);
OnItemsAdded(args.NewStartingIndex(), size);
break;
Expand Down
2 changes: 1 addition & 1 deletion dev/Repeater/ItemsRepeater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ void ItemsRepeater::OnLayoutChanged(const winrt::Layout& oldValue, const winrt::
m_arrangeInvalidated = newValue.ArrangeInvalidated(winrt::auto_revoke, { this, &ItemsRepeater::InvalidateArrangeForLayout });
}

bool isVirtualizingLayout = newValue != nullptr && newValue.try_as<winrt::VirtualizingLayout>() != nullptr;
const bool isVirtualizingLayout = newValue != nullptr && newValue.try_as<winrt::VirtualizingLayout>() != nullptr;
m_viewportManager->OnLayoutChanged(isVirtualizingLayout);
InvalidateMeasure();
}
Expand Down
Loading