Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Checks:
- -readability-magic-numbers # Maybe we can revisit later, but for now this is too noisy
- -readability-named-parameter # Too noisy, negatively impacts the use of tag types, and generally not that useful of a check
- -readability-qualified-auto # Changes 'auto' to 'auto*' for pointers... Not really all that useful and kind of annoying for HANDLE
- -readability-use-concise-preprocessor-directives # Suggests 'elif(n)def' with >= C++23, but we need to support down to C++17 and there's no option to suppress
CheckOptions:
bugprone-empty-catch.IgnoreCatchWithKeywords: 'Fall through'
misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: true # Makes this check more tolerable
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,36 @@ jobs:
exit /b 1
)

clang-tidy:
name: Clang-Tidy Check
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install/Update Clang
shell: cmd
run: |
choco upgrade llvm -y
if %ERRORLEVEL% NEQ 0 exit /b %ERRORLEVEL%

REM This is somewhat of a hack... we want to use the path to LLVM instead of MSVC's LLVM installation, but
REM _only_ when we're actually building with Clang. This is taking advantage of the fact that we're only
REM setting this variable when 'matrix.compiler' is 'clang'.
echo C:\Program Files\LLVM\bin >> %GITHUB_PATH%

- name: Run Clang-Tidy
shell: cmd
run: |
call scripts\call-vcvars.cmd x64
if %ERRORLEVEL% NEQ 0 goto :eof

call scripts\init.cmd -c clang -b relwithdebinfo
if %ERRORLEVEL% NEQ 0 goto :eof

ninja -C build\clang-x64-relwithdebinfo run-clang-tidy

build_and_test:
name: Build and Test
strategy:
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if (${WIL_BUILD_TESTS})
DEPENDS witest.cpplatest # Clang needs the pch, otherwise it fails
USES_TERMINAL # Otherwise, we don't get any output until the command is done, which takes _a while_
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND clang-tidy -p ${PROJECT_BINARY_DIR}/compile_commands.json tests/*.cpp
COMMAND clang-tidy -p ${PROJECT_BINARY_DIR}/compile_commands.json --warnings-as-errors=* tests/*.cpp
)
endif()
endif()
Expand Down
8 changes: 4 additions & 4 deletions include/wil/com.h
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ class com_ptr_t
// Prefast cannot see through the error policy + query_policy mapping and as a result fires 6388 and 28196 for this
// function. Suppression is also not working. Wrapping this entire function in #pragma warning(disable: 6388 28196) does
// not stop all of the prefast errors from being emitted.
#if defined(_PREFAST_)
#ifdef _PREFAST_
*ptrResult = nullptr;
return err_policy::HResult(E_NOINTERFACE);
#else
Expand Down Expand Up @@ -579,7 +579,7 @@ class com_ptr_t
// Prefast cannot see through the error policy + query_policy mapping and as a result and as a result fires 6388 and 28196
// for this function. Suppression is also not working. Wrapping this entire function in #pragma warning(disable: 6388
// 28196) does not stop the prefast errors from being emitted.
#if defined(_PREFAST_)
#ifdef _PREFAST_
*ptrResult = nullptr;
return err_policy::HResult(E_NOINTERFACE);
#else
Expand Down Expand Up @@ -726,7 +726,7 @@ class com_ptr_t
// Prefast cannot see through the error policy + query_policy mapping and as a result and as a result fires 6388 and
// 28196 for this function. Suppression is also not working. Wrapping this entire function in #pragma warning(disable:
// 6388 28196) does not stop the prefast errors from being emitted.
#if defined(_PREFAST_)
#ifdef _PREFAST_
*ptrResult = nullptr;
return err_policy::HResult(E_NOINTERFACE);
#else
Expand Down Expand Up @@ -758,7 +758,7 @@ class com_ptr_t
// Prefast cannot see through the error policy + query_policy mapping and as a result and as a result fires 6388 and
// 28196 for this function. Suppression is also not working. Wrapping this entire function in #pragma warning(disable:
// 6388 28196) does not stop the prefast errors from being emitted.
#if defined(_PREFAST_)
#ifdef _PREFAST_
*ptrResult = nullptr;
return err_policy::HResult(E_NOINTERFACE);
#else
Expand Down
12 changes: 6 additions & 6 deletions include/wil/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
/// @endcond

/// @cond
#if defined(_MSVC_LANG)
#ifdef _MSVC_LANG
#define __WI_SUPPRESS_BREAKING_WARNINGS_S __pragma(warning(push)) __pragma(warning(disable : 4127 26498 4245 26814))
#define __WI_SUPPRESS_BREAKING_WARNINGS_E __pragma(warning(pop))
#define __WI_SUPPRESS_NULLPTR_ANALYSIS __pragma(warning(suppress : 28285 6504))
Expand Down Expand Up @@ -331,7 +331,7 @@ extern "C"
#include "wistd_type_traits.h"

//! This macro inserts ODR violation protection; the macro allows it to be compatible with straight "C" code
#if defined(_MSC_VER)
#ifdef _MSC_VER
#define WI_ODR_PRAGMA(NAME, TOKEN) __pragma(detect_mismatch("ODR_violation_" NAME "_mismatch", TOKEN))
#else
#define WI_ODR_PRAGMA(NAME, TOKEN)
Expand Down Expand Up @@ -359,7 +359,7 @@ routines suddenly becoming available. */
#endif

/// @cond
#if defined(WIL_EXCEPTION_MODE)
#ifdef WIL_EXCEPTION_MODE
static_assert(WIL_EXCEPTION_MODE <= 2, "Invalid exception mode");
#elif !defined(WIL_LOCK_EXCEPTION_MODE)
#define WIL_EXCEPTION_MODE 0 // default, can link exception-based and non-exception based libraries together
Expand Down Expand Up @@ -430,7 +430,7 @@ deduce whether or not the STL is available and can be safely used.
/// @endcond

// block for documentation only
#if defined(WIL_DOXYGEN)
#ifdef WIL_DOXYGEN
/** This define can be explicitly set to disable exception usage within wil.
Normally this define is never needed as the WIL_ENABLE_EXCEPTIONS macro is enabled automatically by looking
at _CPPUNWIND. If your code compiles with exceptions enabled, but does not want to enable the exception-based
Expand Down Expand Up @@ -632,7 +632,7 @@ namespace details

//! @} // group bitwise

#if defined(WIL_DOXYGEN)
#ifdef WIL_DOXYGEN
/** This macro provides a C++ header with a guaranteed initialization function.
Normally, were a global object's constructor used for this purpose, the optimizer/linker might throw
the object away if it's unreferenced (which throws away the side-effects that the initialization function
Expand All @@ -657,7 +657,7 @@ desktop APIs. Building this functionality as `#IFDEF`s within functions would c
doing it with global function pointers and header initialization allows a runtime determination. */
#define WI_HEADER_INITIALIZATION_FUNCTION(name, fn)
#elif defined(_M_IX86) || defined(_M_IA64) || defined(_M_AMD64) || defined(_M_ARM) || defined(_M_ARM64)
#if defined(_MSC_VER)
#ifdef _MSC_VER
#ifdef _M_IX86
#define WI_HEADER_INITIALIZATION_FUNCTION(name, fn) \
extern "C" \
Expand Down
2 changes: 1 addition & 1 deletion include/wil/coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@

// Detect which version of the coroutine standard we have.
/// @cond
#if defined(_RESUMABLE_FUNCTIONS_SUPPORTED)
#ifdef _RESUMABLE_FUNCTIONS_SUPPORTED
#include <experimental/coroutine>
#define __WI_COROUTINE_NAMESPACE ::std::experimental
#elif defined(__cpp_impl_coroutine)
Expand Down
2 changes: 1 addition & 1 deletion include/wil/cppwinrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ constexpr int version_from_string(const char* versionString)
int result = 0;
while ((*versionString >= '0') && (*versionString <= '9'))
{
result = result * 10 + (*versionString - '0');
result = (result * 10) + (*versionString - '0');
++versionString;
}

Expand Down
2 changes: 1 addition & 1 deletion include/wil/cppwinrt_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ template <typename Dispatcher>
struct dispatcher_traits;
} // namespace wil::details

#if defined(_RESUMABLE_FUNCTIONS_SUPPORTED)
#ifdef _RESUMABLE_FUNCTIONS_SUPPORTED
#include <experimental/coroutine>
namespace wil::details
{
Expand Down
14 changes: 7 additions & 7 deletions include/wil/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace network
return {};
}

#if defined(WIL_ENABLE_EXCEPTIONS)
#ifdef WIL_ENABLE_EXCEPTIONS
// Calls WSAStartup and throws on error; returns an RAII object that reverts
WI_NODISCARD inline ::wil::network::unique_wsacleanup_call WSAStartup()
{
Expand Down Expand Up @@ -173,7 +173,7 @@ namespace network
explicit socket_address(const SOCKET_ADDRESS* addr) WI_NOEXCEPT;
explicit socket_address(const IN_ADDR* addr, unsigned short port = 0) WI_NOEXCEPT;
explicit socket_address(const IN6_ADDR* addr, unsigned short port = 0) WI_NOEXCEPT;
#if defined(WIL_ENABLE_EXCEPTIONS)
#ifdef WIL_ENABLE_EXCEPTIONS
explicit socket_address(PCWSTR addr, unsigned short port = 0);
#endif

Expand Down Expand Up @@ -202,7 +202,7 @@ namespace network
void set_address(const IN_ADDR* addr) WI_NOEXCEPT;
void set_address(const IN6_ADDR* addr) WI_NOEXCEPT;

#if defined(WIL_ENABLE_EXCEPTIONS)
#ifdef WIL_ENABLE_EXCEPTIONS
void reset_address(SOCKET s);
void reset_address(PCWSTR address);
void reset_address(PCSTR address);
Expand Down Expand Up @@ -407,7 +407,7 @@ namespace network
// not defining a type for ADDRINFOEXA as that type is formally __declspec(deprecated)
using addr_infoex_iterator = addr_info_iterator_t<ADDRINFOEXW>;

#if defined(WIL_ENABLE_EXCEPTIONS)
#ifdef WIL_ENABLE_EXCEPTIONS
// function to capture resolving IP addresses assigned to the local machine, throwing on error
// returning an RAII object containing the results
inline ::wil::unique_addrinfo resolve_name(PCWSTR name)
Expand Down Expand Up @@ -711,7 +711,7 @@ namespace network
set_port(port);
}

#if defined(WIL_ENABLE_EXCEPTIONS)
#ifdef WIL_ENABLE_EXCEPTIONS
inline socket_address::socket_address(PCWSTR addr, unsigned short port)
{
reset_address(addr);
Expand Down Expand Up @@ -1020,7 +1020,7 @@ namespace network
m_sockaddr.Ipv6.sin6_port = original_port;
}

#if defined(WIL_ENABLE_EXCEPTIONS)
#ifdef WIL_ENABLE_EXCEPTIONS
inline void socket_address::reset_address(SOCKET s)
{
THROW_IF_FAILED(reset_address_nothrow(s));
Expand Down Expand Up @@ -1176,7 +1176,7 @@ namespace network
}

// the Winsock headers require having set this #define to access ANSI-string versions of the Winsock API
#if defined(_WINSOCK_DEPRECATED_NO_WARNINGS)
#ifdef _WINSOCK_DEPRECATED_NO_WARNINGS
inline HRESULT socket_address::format_complete_address_nothrow(socket_address_string& address) const WI_NOEXCEPT
{
::memset(address, 0, sizeof(socket_address_string));
Expand Down
32 changes: 16 additions & 16 deletions include/wil/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace wil
//! Functions and classes that support reading and writing values to/from the registry.
namespace reg
{
#if defined(WIL_ENABLE_EXCEPTIONS)
#ifdef WIL_ENABLE_EXCEPTIONS
/**
* @brief Opens a new HKEY to the specified path - see RegOpenKeyExW
* @param key An open or well-known registry key
Expand Down Expand Up @@ -101,7 +101,7 @@ namespace reg
return return_value;
}
#endif // #if defined(__WIL_WINREG_STL)
#endif // #if defined(WIL_ENABLE_EXCEPTIONS)
#endif // #ifdef WIL_ENABLE_EXCEPTIONS

/**
* @brief Opens a new HKEY to the specified path - see RegOpenKeyExW
Expand Down Expand Up @@ -221,7 +221,7 @@ namespace reg
// // the HRESULT last_error() returns the registry error that prevented enumeration
// }
//
#if defined(WIL_ENABLE_EXCEPTIONS)
#ifdef WIL_ENABLE_EXCEPTIONS

#if WIL_USE_STL || defined(WIL_DOXYGEN)
using key_iterator = ::wil::reg::iterator_t<::wil::reg::key_iterator_data<::std::wstring>>;
Expand All @@ -236,7 +236,7 @@ namespace reg
using key_heap_string_iterator = ::wil::reg::iterator_t<::wil::reg::key_iterator_data<::wil::unique_process_heap_string>>;
using value_heap_string_iterator = ::wil::reg::iterator_t<::wil::reg::value_iterator_data<::wil::unique_process_heap_string>>;

#endif // #if defined(WIL_ENABLE_EXCEPTIONS)
#endif // #ifdef WIL_ENABLE_EXCEPTIONS

// no-throw versions of applicable registry iterators
#if defined(__WIL_OLEAUTO_H_) || defined(WIL_DOXYGEN)
Expand Down Expand Up @@ -337,7 +337,7 @@ namespace reg
return S_OK;
}

#if defined(WIL_ENABLE_EXCEPTIONS)
#ifdef WIL_ENABLE_EXCEPTIONS
/**
* @brief Queries for number of sub-keys
* @param key The HKEY to query for number of sub-keys
Expand Down Expand Up @@ -376,9 +376,9 @@ namespace reg
THROW_IF_FAILED(::wil::reg::get_last_write_filetime_nothrow(key, &lastModified));
return lastModified;
}
#endif // #if defined(WIL_ENABLE_EXCEPTIONS)
#endif // #ifdef WIL_ENABLE_EXCEPTIONS

#if defined(WIL_ENABLE_EXCEPTIONS)
#ifdef WIL_ENABLE_EXCEPTIONS
//
// template <typename T>
// void set_value(...)
Expand Down Expand Up @@ -920,7 +920,7 @@ namespace reg
}
#endif

#if defined(WIL_ENABLE_EXCEPTIONS)
#ifdef WIL_ENABLE_EXCEPTIONS
//
// template <typename T>
// T get_value(...)
Expand Down Expand Up @@ -1720,14 +1720,14 @@ namespace reg
template <typename T>
::std::optional<T> try_get_value(HKEY key, _In_opt_ PCWSTR subkey, _In_opt_ PCWSTR value_name)
{
#if defined(__WIL_OLEAUTO_H_)
#ifdef __WIL_OLEAUTO_H_
// not allowing unique types with try_get_value: wil::unique_bstr cannot be copied and thus is difficult to work with a std::optional
static_assert(!wistd::is_same_v<T, ::wil::unique_bstr>, "try_get with wil::unique_bstr is disabled");
#endif // #if defined(__WIL_OLEAUTO_H_)
#if defined(__WIL_OBJBASE_H_)
#endif // #ifdef __WIL_OLEAUTO_H_
#ifdef __WIL_OBJBASE_H_
// not allowing unique types with try_get_value: wil::unique_cotaskmem_string cannot be copied and thus is difficult to work with a std::optional
static_assert(!wistd::is_same_v<T, ::wil::unique_cotaskmem_string>, "try_get with wil::unique_cotaskmem_string is disabled");
#endif // #if defined(__WIL_OBJBASE_H_)
#endif // #ifdef __WIL_OBJBASE_H_

const reg_view_details::reg_view regview{key};
return regview.try_get_value<T>(subkey, value_name);
Expand All @@ -1747,14 +1747,14 @@ namespace reg
template <typename T>
::std::optional<T> try_get_value(HKEY key, _In_opt_ PCWSTR value_name)
{
#if defined(__WIL_OLEAUTO_H_)
#ifdef __WIL_OLEAUTO_H_
// not allowing unique types with try_get_value: wil::unique_bstr cannot be copied and thus is difficult to work with a std::optional
static_assert(!wistd::is_same_v<T, ::wil::unique_bstr>, "try_get with wil::unique_bstr is disabled");
#endif // #if defined(__WIL_OLEAUTO_H_)
#if defined(__WIL_OBJBASE_H_)
#endif // #ifdef __WIL_OLEAUTO_H_
#ifdef __WIL_OBJBASE_H_
// not allowing unique types with try_get_value: wil::unique_cotaskmem_string cannot be copied and thus is difficult to work with a std::optional
static_assert(!wistd::is_same_v<T, ::wil::unique_cotaskmem_string>, "try_get with wil::unique_cotaskmem_string is disabled");
#endif // #if defined(__WIL_OBJBASE_H_)
#endif // #ifdef __WIL_OBJBASE_H_

return ::wil::reg::try_get_value<T>(key, nullptr, value_name);
}
Expand Down
Loading