Commit 95ac37de authored by Robert Liao's avatar Robert Liao Committed by Commit Bot

Run clang-tidy modernize-use-using on //base/win

All changes were performed by clang-tidy except for the following:
  * Reverted windows_types.h as they need to appear exactly as they do
    in windows.h and there isn't anyway to exclude files from
    clang-tidy (https://reviews.llvm.org/D26418)
  * clang-tidy doesn't quite handle WINAPI and cdecl rewrites correctly.
    Those are manually fixed up in
      * scoped_handle_unittest.cc
      * win_util.cc
      * wrapped_window_proc.h

BUG=1034666

Change-Id: I20921cd09922072767caaed4a79de179e8bf4819
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1989979
Commit-Queue: Robert Liao <robliao@chromium.org>
Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Auto-Submit: Robert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732685}
parent effb01a5
...@@ -17,6 +17,7 @@ Checks: '-*, ...@@ -17,6 +17,7 @@ Checks: '-*,
modernize-use-nullptr, modernize-use-nullptr,
modernize-use-override, modernize-use-override,
modernize-use-transparent-functors, modernize-use-transparent-functors,
modernize-use-using,
readability-redundant-member-init' readability-redundant-member-init'
HeaderFilterRegex: 'base/win/*' HeaderFilterRegex: 'base/win/*'
CheckOptions: CheckOptions:
......
...@@ -29,7 +29,7 @@ namespace win { ...@@ -29,7 +29,7 @@ namespace win {
namespace { namespace {
typedef std::list<EVENT_TRACE> EventQueue; using EventQueue = std::list<EVENT_TRACE>;
class TestConsumer : public EtwTraceConsumerBase<TestConsumer> { class TestConsumer : public EtwTraceConsumerBase<TestConsumer> {
public: public:
......
...@@ -23,11 +23,11 @@ ...@@ -23,11 +23,11 @@
namespace base { namespace base {
namespace win { namespace win {
typedef GUID EtwEventClass; using EtwEventClass = GUID;
typedef UCHAR EtwEventType; using EtwEventType = UCHAR;
typedef UCHAR EtwEventLevel; using EtwEventLevel = UCHAR;
typedef USHORT EtwEventVersion; using EtwEventVersion = USHORT;
typedef ULONG EtwEventFlags; using EtwEventFlags = ULONG;
// Base class is a POD for correctness. // Base class is a POD for correctness.
template <size_t N> template <size_t N>
...@@ -40,7 +40,7 @@ struct EtwMofEventBase { ...@@ -40,7 +40,7 @@ struct EtwMofEventBase {
template <size_t N> template <size_t N>
class EtwMofEvent : public EtwMofEventBase<N> { class EtwMofEvent : public EtwMofEventBase<N> {
public: public:
typedef EtwMofEventBase<N> Super; using Super = EtwMofEventBase<N>;
// Clang and the C++ standard don't allow unqualified lookup into dependent // Clang and the C++ standard don't allow unqualified lookup into dependent
// bases, hence these using decls to explicitly pull the names out. // bases, hence these using decls to explicitly pull the names out.
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
namespace { namespace {
typedef decltype(::GetSystemPreferredUILanguages)* GetPreferredUILanguages_Fn; using GetPreferredUILanguages_Fn = decltype(::GetSystemPreferredUILanguages)*;
bool GetPreferredUILanguageList(GetPreferredUILanguages_Fn function, bool GetPreferredUILanguageList(GetPreferredUILanguages_Fn function,
ULONG flags, ULONG flags,
......
...@@ -32,65 +32,54 @@ class PEImage { ...@@ -32,65 +32,54 @@ class PEImage {
// Callback to enumerate sections. // Callback to enumerate sections.
// cookie is the value passed to the enumerate method. // cookie is the value passed to the enumerate method.
// Returns true to continue the enumeration. // Returns true to continue the enumeration.
typedef bool (*EnumSectionsFunction)(const PEImage& image, using EnumSectionsFunction =
PIMAGE_SECTION_HEADER header, bool (*)(const PEImage&, PIMAGE_SECTION_HEADER, PVOID, DWORD, PVOID);
PVOID section_start,
DWORD section_size,
PVOID cookie);
// Callback to enumerate exports. // Callback to enumerate exports.
// function is the actual address of the symbol. If forward is not null, it // function is the actual address of the symbol. If forward is not null, it
// contains the dll and symbol to forward this export to. cookie is the value // contains the dll and symbol to forward this export to. cookie is the value
// passed to the enumerate method. // passed to the enumerate method.
// Returns true to continue the enumeration. // Returns true to continue the enumeration.
typedef bool (*EnumExportsFunction)(const PEImage& image, using EnumExportsFunction =
DWORD ordinal, bool (*)(const PEImage&, DWORD, DWORD, LPCSTR, PVOID, LPCSTR, PVOID);
DWORD hint,
LPCSTR name,
PVOID function,
LPCSTR forward,
PVOID cookie);
// Callback to enumerate import blocks. // Callback to enumerate import blocks.
// name_table and iat point to the imports name table and address table for // name_table and iat point to the imports name table and address table for
// this block. cookie is the value passed to the enumerate method. // this block. cookie is the value passed to the enumerate method.
// Returns true to continue the enumeration. // Returns true to continue the enumeration.
typedef bool (*EnumImportChunksFunction)(const PEImage& image, using EnumImportChunksFunction = bool (*)(const PEImage&,
LPCSTR module, LPCSTR,
PIMAGE_THUNK_DATA name_table, PIMAGE_THUNK_DATA,
PIMAGE_THUNK_DATA iat, PIMAGE_THUNK_DATA,
PVOID cookie); PVOID);
// Callback to enumerate imports. // Callback to enumerate imports.
// module is the dll that exports this symbol. cookie is the value passed to // module is the dll that exports this symbol. cookie is the value passed to
// the enumerate method. // the enumerate method.
// Returns true to continue the enumeration. // Returns true to continue the enumeration.
typedef bool (*EnumImportsFunction)(const PEImage& image, using EnumImportsFunction = bool (*)(const PEImage&,
LPCSTR module, LPCSTR,
DWORD ordinal, DWORD,
LPCSTR name, LPCSTR,
DWORD hint, DWORD,
PIMAGE_THUNK_DATA iat, PIMAGE_THUNK_DATA,
PVOID cookie); PVOID);
// Callback to enumerate delayed import blocks. // Callback to enumerate delayed import blocks.
// module is the dll that exports this block of symbols. cookie is the value // module is the dll that exports this block of symbols. cookie is the value
// passed to the enumerate method. // passed to the enumerate method.
// Returns true to continue the enumeration. // Returns true to continue the enumeration.
typedef bool (*EnumDelayImportChunksFunction)(const PEImage& image, using EnumDelayImportChunksFunction = bool (*)(const PEImage&,
PImgDelayDescr delay_descriptor, PImgDelayDescr,
LPCSTR module, LPCSTR,
PIMAGE_THUNK_DATA name_table, PIMAGE_THUNK_DATA,
PIMAGE_THUNK_DATA iat, PIMAGE_THUNK_DATA,
PVOID cookie); PVOID);
// Callback to enumerate relocations. // Callback to enumerate relocations.
// cookie is the value passed to the enumerate method. // cookie is the value passed to the enumerate method.
// Returns true to continue the enumeration. // Returns true to continue the enumeration.
typedef bool (*EnumRelocsFunction)(const PEImage& image, using EnumRelocsFunction = bool (*)(const PEImage&, WORD, PVOID, PVOID);
WORD type,
PVOID address,
PVOID cookie);
explicit PEImage(HMODULE module) : module_(module) {} explicit PEImage(HMODULE module) : module_(module) {}
explicit PEImage(const void* module) { explicit PEImage(const void* module) {
......
...@@ -38,7 +38,7 @@ namespace win { ...@@ -38,7 +38,7 @@ namespace win {
template <class Traits, class Verifier> template <class Traits, class Verifier>
class GenericScopedHandle { class GenericScopedHandle {
public: public:
typedef typename Traits::Handle Handle; using Handle = typename Traits::Handle;
GenericScopedHandle() : handle_(Traits::NullHandle()) {} GenericScopedHandle() : handle_(Traits::NullHandle()) {}
...@@ -113,7 +113,7 @@ class GenericScopedHandle { ...@@ -113,7 +113,7 @@ class GenericScopedHandle {
// The traits class for Win32 handles that can be closed via CloseHandle() API. // The traits class for Win32 handles that can be closed via CloseHandle() API.
class HandleTraits { class HandleTraits {
public: public:
typedef HANDLE Handle; using Handle = HANDLE;
// Closes the handle. // Closes the handle.
static bool BASE_EXPORT CloseHandle(HANDLE handle); static bool BASE_EXPORT CloseHandle(HANDLE handle);
...@@ -133,7 +133,7 @@ class HandleTraits { ...@@ -133,7 +133,7 @@ class HandleTraits {
// Do-nothing verifier. // Do-nothing verifier.
class DummyVerifierTraits { class DummyVerifierTraits {
public: public:
typedef HANDLE Handle; using Handle = HANDLE;
static void StartTracking(HANDLE handle, static void StartTracking(HANDLE handle,
const void* owner, const void* owner,
...@@ -151,7 +151,7 @@ class DummyVerifierTraits { ...@@ -151,7 +151,7 @@ class DummyVerifierTraits {
// Performs actual run-time tracking. // Performs actual run-time tracking.
class BASE_EXPORT VerifierTraits { class BASE_EXPORT VerifierTraits {
public: public:
typedef HANDLE Handle; using Handle = HANDLE;
static void StartTracking(HANDLE handle, static void StartTracking(HANDLE handle,
const void* owner, const void* owner,
...@@ -166,7 +166,7 @@ class BASE_EXPORT VerifierTraits { ...@@ -166,7 +166,7 @@ class BASE_EXPORT VerifierTraits {
DISALLOW_IMPLICIT_CONSTRUCTORS(VerifierTraits); DISALLOW_IMPLICIT_CONSTRUCTORS(VerifierTraits);
}; };
typedef GenericScopedHandle<HandleTraits, VerifierTraits> ScopedHandle; using ScopedHandle = GenericScopedHandle<HandleTraits, VerifierTraits>;
// This function may be called by the embedder to disable the use of // This function may be called by the embedder to disable the use of
// VerifierTraits at runtime. It has no effect if DummyVerifierTraits is used // VerifierTraits at runtime. It has no effect if DummyVerifierTraits is used
......
...@@ -52,7 +52,7 @@ TEST(ScopedHandleTest, ScopedHandle) { ...@@ -52,7 +52,7 @@ TEST(ScopedHandleTest, ScopedHandle) {
TEST(ScopedHandleTest, ActiveVerifierTrackedHasBeenClosed) { TEST(ScopedHandleTest, ActiveVerifierTrackedHasBeenClosed) {
HANDLE handle = ::CreateMutex(nullptr, false, nullptr); HANDLE handle = ::CreateMutex(nullptr, false, nullptr);
ASSERT_NE(HANDLE(nullptr), handle); ASSERT_NE(HANDLE(nullptr), handle);
typedef NTSTATUS(WINAPI * NtCloseFunc)(HANDLE); using NtCloseFunc = decltype(&::NtClose);
NtCloseFunc ntclose = reinterpret_cast<NtCloseFunc>( NtCloseFunc ntclose = reinterpret_cast<NtCloseFunc>(
GetProcAddress(GetModuleHandle(L"ntdll.dll"), "NtClose")); GetProcAddress(GetModuleHandle(L"ntdll.dll"), "NtClose"));
ASSERT_NE(nullptr, ntclose); ASSERT_NE(nullptr, ntclose);
......
...@@ -27,12 +27,12 @@ void* GetHandleVerifier() { ...@@ -27,12 +27,12 @@ void* GetHandleVerifier() {
namespace { namespace {
base::win::internal::ScopedHandleVerifier* g_active_verifier = nullptr; base::win::internal::ScopedHandleVerifier* g_active_verifier = nullptr;
typedef void* (*GetHandleVerifierFn)(); using GetHandleVerifierFn = void* (*)();
typedef std::unordered_map<HANDLE, using HandleMap =
base::win::internal::ScopedHandleVerifierInfo, std::unordered_map<HANDLE,
base::win::internal::HandleHash> base::win::internal::ScopedHandleVerifierInfo,
HandleMap; base::win::internal::HandleHash>;
typedef base::internal::LockImpl NativeLock; using NativeLock = base::internal::LockImpl;
NativeLock* GetLock() { NativeLock* GetLock() {
static auto* native_lock = new NativeLock(); static auto* native_lock = new NativeLock();
......
...@@ -289,7 +289,7 @@ bool IsKeyboardPresentOnSlate(HWND hwnd, std::string* reason) { ...@@ -289,7 +289,7 @@ bool IsKeyboardPresentOnSlate(HWND hwnd, std::string* reason) {
// 3. If step 1 and 2 fail then we check attached keyboards and return true // 3. If step 1 and 2 fail then we check attached keyboards and return true
// if we find ACPI\* or HID\VID* keyboards. // if we find ACPI\* or HID\VID* keyboards.
typedef BOOL(WINAPI * GetAutoRotationState)(PAR_STATE state); using GetAutoRotationState = decltype(&::GetAutoRotationState);
static const auto get_rotation_state = reinterpret_cast<GetAutoRotationState>( static const auto get_rotation_state = reinterpret_cast<GetAutoRotationState>(
GetUser32FunctionPointer("GetAutoRotationState")); GetUser32FunctionPointer("GetAutoRotationState"));
if (get_rotation_state) { if (get_rotation_state) {
...@@ -550,7 +550,7 @@ bool IsDeviceUsedAsATablet(std::string* reason) { ...@@ -550,7 +550,7 @@ bool IsDeviceUsedAsATablet(std::string* reason) {
// a convertible or a detachable. // a convertible or a detachable.
// See // See
// https://msdn.microsoft.com/en-us/library/windows/desktop/dn629263(v=vs.85).aspx // https://msdn.microsoft.com/en-us/library/windows/desktop/dn629263(v=vs.85).aspx
typedef decltype(GetAutoRotationState)* GetAutoRotationStateType; using GetAutoRotationStateType = decltype(GetAutoRotationState)*;
static const auto get_auto_rotation_state_func = static const auto get_auto_rotation_state_func =
reinterpret_cast<GetAutoRotationStateType>( reinterpret_cast<GetAutoRotationStateType>(
GetUser32FunctionPointer("GetAutoRotationState")); GetUser32FunctionPointer("GetAutoRotationState"));
...@@ -601,8 +601,8 @@ bool IsUser32AndGdi32Available() { ...@@ -601,8 +601,8 @@ bool IsUser32AndGdi32Available() {
if (GetVersion() < Version::WIN8) if (GetVersion() < Version::WIN8)
return true; return true;
typedef decltype( using GetProcessMitigationPolicyType =
GetProcessMitigationPolicy)* GetProcessMitigationPolicyType; decltype(GetProcessMitigationPolicy)*;
GetProcessMitigationPolicyType get_process_mitigation_policy_func = GetProcessMitigationPolicyType get_process_mitigation_policy_func =
reinterpret_cast<GetProcessMitigationPolicyType>(GetProcAddress( reinterpret_cast<GetProcessMitigationPolicyType>(GetProcAddress(
GetModuleHandle(L"kernel32.dll"), "GetProcessMitigationPolicy")); GetModuleHandle(L"kernel32.dll"), "GetProcessMitigationPolicy"));
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
struct IPropertyStore; struct IPropertyStore;
struct _tagpropertykey; struct _tagpropertykey;
typedef _tagpropertykey PROPERTYKEY; using PROPERTYKEY = _tagpropertykey;
namespace base { namespace base {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/version.h" #include "base/version.h"
typedef void* HANDLE; using HANDLE = void*;
struct _OSVERSIONINFOEXW; struct _OSVERSIONINFOEXW;
struct _SYSTEM_INFO; struct _SYSTEM_INFO;
......
...@@ -23,7 +23,7 @@ namespace win { ...@@ -23,7 +23,7 @@ namespace win {
// expected behavior for this function is to not return, instead of returning // expected behavior for this function is to not return, instead of returning
// EXCEPTION_EXECUTE_HANDLER or similar, given that in general we are not // EXCEPTION_EXECUTE_HANDLER or similar, given that in general we are not
// prepared to handle exceptions. // prepared to handle exceptions.
typedef int(__cdecl* WinProcExceptionFilter)(EXCEPTION_POINTERS* info); using WinProcExceptionFilter = int __cdecl (*)(EXCEPTION_POINTERS* info);
// Sets the filter to deal with exceptions inside a WindowProc. Returns the old // Sets the filter to deal with exceptions inside a WindowProc. Returns the old
// exception filter, if any. // exception filter, if any.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment