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

Apply [[nodiscard]] to functions returning error codes #953

Merged
3 commits merged into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
3 changes: 3 additions & 0 deletions src/cascadia/WindowsTerminal/BaseWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class BaseWindow
return reinterpret_cast<T *>(GetWindowLongPtr(window, GWLP_USERDATA));
}

[[nodiscard]]
static LRESULT __stdcall WndProc(HWND const window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept
{
WINRT_ASSERT(window);
Expand All @@ -40,6 +41,7 @@ class BaseWindow
return DefWindowProc(window, message, wparam, lparam);
}

[[nodiscard]]
virtual LRESULT MessageHandler(UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept
{
switch (message) {
Expand Down Expand Up @@ -98,6 +100,7 @@ class BaseWindow
}

// DPI Change handler. on WM_DPICHANGE resize the window
[[nodiscard]]
LRESULT HandleDpiChange(const HWND hWnd, const WPARAM wParam, const LPARAM lParam)
{
_inDpiChange = true;
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void IslandWindow::OnSize()
}
}

[[nodiscard]]
LRESULT IslandWindow::MessageHandler(UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept
{
switch (message) {
Expand Down Expand Up @@ -173,7 +174,7 @@ LRESULT IslandWindow::MessageHandler(UINT const message, WPARAM const wparam, LP
// Arguments:
// - width: the new width of the window _in pixels_
// - height: the new height of the window _in pixels_
void IslandWindow::OnResize(const UINT width, const UINT height)
void IslandWindow::OnResize(const UINT /*width*/, const UINT /*height*/)
{
OnSize();
}
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/WindowsTerminal/IslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class IslandWindow : public BaseWindow<IslandWindow>
void Close();
virtual void OnSize();

[[nodiscard]]
virtual LRESULT MessageHandler(UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept override;
void OnResize(const UINT width, const UINT height) override;
void OnMinimize() override;
Expand Down
9 changes: 6 additions & 3 deletions src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ void NonClientIslandWindow::OnSize()
// NOTE:
// Largely taken from code on:
// https://docs.microsoft.com/en-us/windows/desktop/dwm/customframe
[[nodiscard]]
LRESULT NonClientIslandWindow::HitTestNCA(POINT ptMouse) const noexcept
{
// Get the window rectangle.
Expand Down Expand Up @@ -284,6 +285,7 @@ MARGINS NonClientIslandWindow::GetFrameMargins() const noexcept
// - <none>
// Return Value:
// - the HRESULT returned by DwmExtendFrameIntoClientArea.
[[nodiscard]]
HRESULT NonClientIslandWindow::_UpdateFrameMargins() const noexcept
{
// Get the size of the borders we want to use. The sides and bottom will
Expand Down Expand Up @@ -387,6 +389,7 @@ RECT NonClientIslandWindow::GetMaxWindowRectInPixels(const RECT * const prcSugge
// Return Value:
// - The return value is the result of the message processing and depends on the
// message sent.
[[nodiscard]]
LRESULT NonClientIslandWindow::MessageHandler(UINT const message,
WPARAM const wParam,
LPARAM const lParam) noexcept
Expand Down Expand Up @@ -489,7 +492,7 @@ void NonClientIslandWindow::_HandleActivateWindow()
// _titlebarUnscaledContentHeight is set with SetNonClientHeight by the app
// hosting us.

_UpdateFrameMargins();
THROW_IF_FAILED(_UpdateFrameMargins());
binarycrusader marked this conversation as resolved.
Show resolved Hide resolved
}

// Method Description:
Expand Down Expand Up @@ -633,7 +636,7 @@ bool NonClientIslandWindow::_HandleWindowPosChanging(WINDOWPOS* const windowPos)
_maximizedMargins.cyBottomHeight = -offset;

_isMaximized = true;
_UpdateFrameMargins();
THROW_IF_FAILED(_UpdateFrameMargins());
binarycrusader marked this conversation as resolved.
Show resolved Hide resolved
}
}
else
Expand All @@ -647,7 +650,7 @@ bool NonClientIslandWindow::_HandleWindowPosChanging(WINDOWPOS* const windowPos)
// keep this here _in general_ for dragging across DPI boundaries.
if (!_isMaximized)
{
_UpdateFrameMargins();
THROW_IF_FAILED(_UpdateFrameMargins());
binarycrusader marked this conversation as resolved.
Show resolved Hide resolved
}

_isMaximized = false;
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/WindowsTerminal/NonClientIslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class NonClientIslandWindow : public IslandWindow

virtual void OnSize() override;

[[nodiscard]]
virtual LRESULT MessageHandler(UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept override;

void SetNonClientContent(winrt::Windows::UI::Xaml::UIElement content);
Expand Down Expand Up @@ -62,7 +63,10 @@ class NonClientIslandWindow : public IslandWindow
MARGINS _maximizedMargins;
bool _isMaximized;

[[nodiscard]]
LRESULT HitTestNCA(POINT ptMouse) const noexcept;

[[nodiscard]]
HRESULT _UpdateFrameMargins() const noexcept;

void _HandleActivateWindow();
Expand Down
1 change: 0 additions & 1 deletion src/host/ConsoleArguments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class ConsoleArguments
[[nodiscard]]
HRESULT ParseCommandline();

bool IsUsingVtPipe() const;
binarycrusader marked this conversation as resolved.
Show resolved Hide resolved
bool HasVtHandles() const;
bool InConptyMode() const noexcept;
bool IsHeadless() const;
Expand Down
2 changes: 1 addition & 1 deletion src/host/VtIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ HRESULT VtIo::Initialize(const ConsoleArguments * const pArgs)
// S_OK if we initialized successfully, otherwise an appropriate HRESULT
// indicating failure.
[[nodiscard]]
HRESULT VtIo::_Initialize(const HANDLE InHandle, const HANDLE OutHandle, const std::wstring& VtMode, const HANDLE SignalHandle)
HRESULT VtIo::_Initialize(const HANDLE InHandle, const HANDLE OutHandle, const std::wstring& VtMode, _In_opt_ const HANDLE SignalHandle)
binarycrusader marked this conversation as resolved.
Show resolved Hide resolved
{
FAIL_FAST_IF_MSG(_initialized, "Someone attempted to double-_Initialize VtIo");

Expand Down
4 changes: 1 addition & 3 deletions src/host/VtIo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ namespace Microsoft::Console::VirtualTerminal
std::unique_ptr<Microsoft::Console::PtySignalInputThread> _pPtySignalInputThread;

[[nodiscard]]
HRESULT _Initialize(const HANDLE InHandle, const HANDLE OutHandle, const std::wstring& VtMode);
binarycrusader marked this conversation as resolved.
Show resolved Hide resolved
[[nodiscard]]
HRESULT _Initialize(const HANDLE InHandle, const HANDLE OutHandle, const std::wstring& VtMode, _In_opt_ HANDLE SignalHandle);
HRESULT _Initialize(const HANDLE InHandle, const HANDLE OutHandle, const std::wstring& VtMode, _In_opt_ const HANDLE SignalHandle);
binarycrusader marked this conversation as resolved.
Show resolved Hide resolved

void _ShutdownIfNeeded();

Expand Down
2 changes: 1 addition & 1 deletion src/host/cmdline.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void RedrawCommandLine(COOKED_READ_DATA& cookedReadData);
#define WC_DELAY_EOL_WRAP 0x80

// Word delimiters
bool IsWordDelim(const WCHAR wch);
bool IsWordDelim(const wchar_t wch);
binarycrusader marked this conversation as resolved.
Show resolved Hide resolved
bool IsWordDelim(const std::wstring_view charData);

[[nodiscard]]
Expand Down
2 changes: 2 additions & 0 deletions src/host/popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ void Popup::SetUserInputFunction(UserInputFunction function) noexcept
// - wch - on completion, the char read from the user
// Return Value:
// - relevant NTSTATUS
[[nodiscard]]
NTSTATUS Popup::_getUserInput(COOKED_READ_DATA& cookedReadData, bool& popupKey, DWORD& modifiers, wchar_t& wch) noexcept
{
return _userInputFunction(cookedReadData, popupKey, modifiers, wch);
Expand All @@ -346,6 +347,7 @@ NTSTATUS Popup::_getUserInput(COOKED_READ_DATA& cookedReadData, bool& popupKey,
// - wch - on completion, the char read from the user
// Return Value:
// - relevant NTSTATUS
[[nodiscard]]
NTSTATUS Popup::_getUserInputInternal(COOKED_READ_DATA& cookedReadData,
bool& popupKey,
DWORD& modifiers,
Expand Down
2 changes: 2 additions & 0 deletions src/host/popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Popup
friend class CommandListPopupTests;
#endif

[[nodiscard]]
NTSTATUS _getUserInput(COOKED_READ_DATA& cookedReadData, bool& popupKey, DWORD& modifiers, wchar_t& wch) noexcept;
void _DrawPrompt(const UINT id);
virtual void _DrawContent() = 0;
Expand All @@ -81,6 +82,7 @@ class Popup

void _DrawBorder();

[[nodiscard]]
static NTSTATUS _getUserInputInternal(COOKED_READ_DATA& cookedReadData,
bool& popupKey,
DWORD& modifiers,
Expand Down
1 change: 1 addition & 0 deletions src/inc/test/CommonState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class CommonState
textBuffer.GetCursor().SetYPosition(cRowsToFill);
}

[[nodiscard]]
NTSTATUS GetTextBufferInfoInitResult()
{
return m_ntstatusTextBufferInfo;
Expand Down
3 changes: 3 additions & 0 deletions src/interactivity/inc/IConsoleControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ namespace Microsoft::Console::Interactivity
{
public:
virtual ~IConsoleControl() = 0;
[[nodiscard]]
virtual NTSTATUS NotifyConsoleApplication(DWORD dwProcessId) = 0;
[[nodiscard]]
virtual NTSTATUS SetForeground(HANDLE hProcess, BOOL fForeground) = 0;
[[nodiscard]]
virtual NTSTATUS EndTask(HANDLE hProcessId, DWORD dwEventType, ULONG ulCtrlFlags) = 0;

protected:
Expand Down
2 changes: 2 additions & 0 deletions src/interactivity/win32/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,7 @@ void Window::s_ReinitializeFontsForDPIChange()
gci.GetActiveOutputBuffer().RefreshFontWithRenderer();
}

[[nodiscard]]
LRESULT Window::s_RegPersistWindowPos(_In_ PCWSTR const pwszTitle,
const BOOL fAutoPos,
const Window* const pWindow)
Expand Down Expand Up @@ -1257,6 +1258,7 @@ LRESULT Window::s_RegPersistWindowPos(_In_ PCWSTR const pwszTitle,
return Status;
}

[[nodiscard]]
LRESULT Window::s_RegPersistWindowOpacity(_In_ PCWSTR const pwszTitle, const Window* const pWindow)
{
HKEY hCurrentUserKey, hConsoleKey, hTitleKey;
Expand Down
5 changes: 5 additions & 0 deletions src/interactivity/win32/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ namespace Microsoft::Console::Interactivity::Win32
void _UpdateSystemMetrics() const;

// Wndproc
[[nodiscard]]
static LRESULT CALLBACK s_ConsoleWindowProc(_In_ HWND hwnd,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam);
[[nodiscard]]
LRESULT CALLBACK ConsoleWindowProc(_In_ HWND,
_In_ UINT uMsg,
_In_ WPARAM wParam,
Expand All @@ -137,16 +139,19 @@ namespace Microsoft::Console::Interactivity::Win32
void _HandleWindowPosChanged(const LPARAM lParam);

// Accessibility/UI Automation
[[nodiscard]]
LRESULT _HandleGetObject(const HWND hwnd,
const WPARAM wParam,
const LPARAM lParam);
IRawElementProviderSimple* _GetUiaProvider();
WindowUiaProvider* _pUiaProvider = nullptr;

// Dynamic Settings helpers
[[nodiscard]]
static LRESULT s_RegPersistWindowPos(_In_ PCWSTR const pwszTitle,
const BOOL fAutoPos,
const Window* const pWindow);
[[nodiscard]]
static LRESULT s_RegPersistWindowOpacity(_In_ PCWSTR const pwszTitle,
const Window* const pWindow);

Expand Down
3 changes: 3 additions & 0 deletions src/interactivity/win32/windowproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ using namespace Microsoft::Console::Types;
// The static and specific window procedures for this class are contained here
#pragma region Window Procedure

[[nodiscard]]
LRESULT CALLBACK Window::s_ConsoleWindowProc(_In_ HWND hWnd, _In_ UINT Message, _In_ WPARAM wParam, _In_ LPARAM lParam)
{
// Save the pointer here to the specific window instance when one is created
Expand All @@ -61,6 +62,7 @@ LRESULT CALLBACK Window::s_ConsoleWindowProc(_In_ HWND hWnd, _In_ UINT Message,
return DefWindowProcW(hWnd, Message, wParam, lParam);
}

[[nodiscard]]
LRESULT CALLBACK Window::ConsoleWindowProc(_In_ HWND hWnd, _In_ UINT Message, _In_ WPARAM wParam, _In_ LPARAM lParam)
{
Globals& g = ServiceLocator::LocateGlobals();
Expand Down Expand Up @@ -886,6 +888,7 @@ void Window::_HandleDrop(const WPARAM wParam) const
}
}

[[nodiscard]]
LRESULT Window::_HandleGetObject(const HWND hwnd, const WPARAM wParam, const LPARAM lParam)
{
LRESULT retVal = 0;
Expand Down
1 change: 1 addition & 0 deletions src/propsheet/ColorControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void SimpleColorDoPaint(const HWND hColor, PAINTSTRUCT& ps, const int ColorId)

// Routine Description:
// - Window proc for the color buttons
[[nodiscard]]
LRESULT CALLBACK SimpleColorControlProc(const HWND hColor, const UINT wMsg, const WPARAM wParam, const LPARAM lParam)
{
PAINTSTRUCT ps;
Expand Down
1 change: 1 addition & 0 deletions src/propsheet/ColorControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ Author(s):

#pragma once

[[nodiscard]]
LRESULT CALLBACK SimpleColorControlProc(HWND hColor, UINT wMsg, WPARAM wParam, LPARAM lParam);
void SimpleColorDoPaint(HWND hColor, PAINTSTRUCT& ps, int ColorId);
1 change: 1 addition & 0 deletions src/propsheet/ColorsPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ static int iColor;

// Routine Description:
// - Window proc for the color buttons
[[nodiscard]]
LRESULT CALLBACK ColorTableControlProc(HWND hColor, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
Expand Down
1 change: 1 addition & 0 deletions src/propsheet/ColorsPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ void ToggleV2ColorControls(__in const HWND hDlg);
INT_PTR WINAPI ColorDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
void SetOpacitySlider(__in HWND hDlg);
void PreviewOpacity(HWND hDlg, BYTE bOpacity);
[[nodiscard]]
LRESULT CALLBACK ColorTableControlProc(HWND hColor, UINT wMsg, WPARAM wParam, LPARAM lParam);
1 change: 1 addition & 0 deletions src/propsheet/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ void UnregisterClasses(HINSTANCE hModule)
UnregisterClass(TEXT("WOAFontPreview"), hModule);
}

[[nodiscard]]
HRESULT FindFontAndUpdateState()
{
g_currentFontIndex = FindCreateFont(gpStateInfo->FontFamily,
Expand Down
13 changes: 7 additions & 6 deletions src/propsheet/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@ Revision History:
#define IDS_TOOLTIP_OPACITY 17
#define IDS_TOOLTIP_INTERCEPT_COPY_PASTE 18

NTSTATUS
void
MakeAltRasterFont(
__in UINT CodePage,
__out COORD *AltFontSize,
__out BYTE *AltFontFamily,
__out ULONG *AltFontIndex,
__out_ecount(LF_FACESIZE) LPTSTR AltFaceName);

NTSTATUS InitializeDbcsMisc();
[[nodiscard]]
NTSTATUS InitializeDbcsMisc(VOID);
binarycrusader marked this conversation as resolved.
Show resolved Hide resolved

BYTE
CodePageToCharSet(
Expand Down Expand Up @@ -104,7 +105,7 @@ GetAltFaceName(
LPCTSTR ptszFace
);

NTSTATUS DestroyDbcsMisc();
NTSTATUS DestroyDbcsMisc(VOID);
binarycrusader marked this conversation as resolved.
Show resolved Hide resolved
binarycrusader marked this conversation as resolved.
Show resolved Hide resolved

int
LanguageListCreate(
Expand Down Expand Up @@ -170,15 +171,14 @@ VOID SetRegistryValues(
PCONSOLE_STATE_INFO StateInfo,
DWORD dwPage);

PCONSOLE_STATE_INFO InitStateValues(
binarycrusader marked this conversation as resolved.
Show resolved Hide resolved
HWND hwnd);

[[nodiscard]]
LRESULT CALLBACK FontPreviewWndProc(
HWND hWnd,
UINT wMsg,
WPARAM wParam,
LPARAM lParam);

[[nodiscard]]
LRESULT CALLBACK PreviewWndProc(
HWND hWnd,
UINT wMsg,
Expand All @@ -197,6 +197,7 @@ BOOL UpdateStateInfo(
BOOL InitializeConsoleState();
void UninitializeConsoleState();
void UpdateApplyButton(const HWND hDlg);
[[nodiscard]]
HRESULT FindFontAndUpdateState();

BOOL PopulatePropSheetPageArray(_Out_writes_(cPsps) PROPSHEETPAGE *pPsp, const size_t cPsps, const BOOL fRegisterCallbacks);
Expand Down
Loading