Skip to content

Commit 85b69ba

Browse files
authored
Update for Clang 19 and 20 (#62)
This commit fixes some compilation errors on clang 19 and 20 and with clang-tidy enabled.
1 parent ef716e1 commit 85b69ba

7 files changed

Lines changed: 49 additions & 39 deletions

File tree

.clang-tidy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ Checks: ' -*,
8484
readability-misplaced-array-index,
8585
readability-qualified-auto,
8686
readability-redundant-access-specifiers,
87-
readability-redundant-control-flow,
88-
readability-redundant-member-init,
87+
readability-redundant-control-flow,
8988
readability-redundant-preprocessor,
9089
readability-redundant-smartptr-get,
9190
readability-redundant-string-cstr,
@@ -96,6 +95,7 @@ Checks: ' -*,
9695
readability-string-compare,
9796
readability-uniqueptr-delete-release,
9897
98+
-modernize-avoid-c-arrays,
9999
-modernize-concat-nested-namespaces,
100100
-modernize-raw-string-literal,
101101
-modernize-use-default-member-init,

cmake/SetupCompileFlags.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ function(SETUP_COMPILE_FLAGS)
1616
set(WARNINGS "-Wall;-Wextra;-Werror;-Wunreachable-code")
1717

1818
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
19-
set(WARNINGS "${WARNINGS};-Wpedantic;-Wshadow;-Wno-gnu-zero-variadic-macro-arguments;-Wno-c++98-compat;-Wno-c++98-compat-pedantic;-Wno-exit-time-destructors;-Wno-global-constructors;-Wno-missing-prototypes;-Wno-ctad-maybe-unsupported;-Wno-switch-default")
19+
set(WARNINGS "${WARNINGS};-Wpedantic;-Wshadow;-Wno-gnu-zero-variadic-macro-arguments;-Wno-c++98-compat;-Wno-c++98-compat-pedantic;-Wno-exit-time-destructors;-Wno-global-constructors;-Wno-missing-prototypes;-Wno-ctad-maybe-unsupported;-Wno-switch-default;-Wno-extra-semi-stmt;-Wno-switch-enum")
20+
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.0)
21+
set(WARNINGS "${WARNINGS};-Wno-unsafe-buffer-usage")
22+
endif()
2023
else()
2124
set(WARNINGS "${WARNINGS};-Wshadow=local")
2225

examples/winapi_integration/main.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR, int nCmdShow) {
3333
RECT rect = {0, 0, 800, 600};
3434
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
3535

36-
HWND hwnd =
37-
CreateWindowEx(0, CLASS_NAME, L"Default title", WS_OVERLAPPEDWINDOW,
38-
CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left,
39-
rect.bottom - rect.top, NULL, NULL, hInstance, NULL);
40-
if (hwnd == NULL) {
36+
HWND hwnd = CreateWindowEx(0, CLASS_NAME, L"Default title",
37+
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
38+
rect.right - rect.left, rect.bottom - rect.top,
39+
nullptr, nullptr, hInstance, nullptr);
40+
if (hwnd == nullptr) {
4141
return 0;
4242
}
4343

@@ -63,7 +63,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR, int nCmdShow) {
6363

6464
// Run the message loop.
6565
MSG msg = {};
66-
while (GetMessage(&msg, NULL, 0, 0) > 0) {
66+
while (GetMessage(&msg, nullptr, 0, 0) > 0) {
6767
TranslateMessage(&msg);
6868
DispatchMessage(&msg);
6969
}
@@ -87,7 +87,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd,
8787
case WM_PAINT: {
8888
PAINTSTRUCT ps;
8989
HDC hdc = BeginPaint(hwnd, &ps);
90-
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
90+
FillRect(hdc, &ps.rcPaint, reinterpret_cast<HBRUSH>(COLOR_WINDOW + 1));
9191
EndPaint(hwnd, &ps);
9292
return 0;
9393
}

src/base/bind_internals.h

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ struct FunctorTraitsImpl {
145145
BoundArgumentsTupleType&& bound_arguments,
146146
RunArgumentTypes&&... run_arguments) {
147147
return std::invoke(std::forward<Functor>(functor),
148+
// NOLINTBEGIN(bugprone-use-after-move)
148149
std::get<Indexes>(std::forward<BoundArgumentsTupleType>(
149150
bound_arguments))...,
151+
// NOLINTEND(bugprone-use-after-move)
150152
std::forward<RunArgumentTypes>(run_arguments)...);
151153
}
152154
};
@@ -175,29 +177,30 @@ struct FunctorTraits<ReturnType (*)(ArgumentTypes...)>
175177
sizeof...(ArgumentTypes)> {};
176178

177179
// Member functions
178-
#define LIBBASE_IMPL_MEMBER_FUNCTION_TRAIT(INSTANCE_TYPE, ...) \
179-
template <typename ReturnType, typename ClassType, \
180-
typename... ArgumentTypes> \
181-
struct FunctorTraits<ReturnType (ClassType::*)(ArgumentTypes...) \
182-
__VA_ARGS__> \
183-
: FunctorTraitsImpl<ReturnType, \
184-
std::tuple<INSTANCE_TYPE*, ArgumentTypes...>, \
185-
1 + sizeof...(ArgumentTypes)> { \
186-
template <typename Functor, \
187-
std::size_t... Indexes, \
188-
typename BoundArgumentsTupleType, \
189-
typename... RunArgumentTypes> \
190-
static constexpr decltype(auto) Invoke( \
191-
Functor&& functor, \
192-
std::index_sequence<Indexes...>, \
193-
BoundArgumentsTupleType&& bound_arguments, \
194-
RunArgumentTypes&&... run_arguments) { \
195-
return MemberFunctionInvoke( \
196-
std::forward<Functor>(functor), \
197-
std::get<Indexes>( \
198-
std::forward<BoundArgumentsTupleType>(bound_arguments))..., \
199-
std::forward<RunArgumentTypes>(run_arguments)...); \
200-
} \
180+
#define LIBBASE_IMPL_MEMBER_FUNCTION_TRAIT(INSTANCE_TYPE, ...) \
181+
template <typename ReturnType, typename ClassType, \
182+
typename... ArgumentTypes> \
183+
struct FunctorTraits<ReturnType (ClassType::*)(ArgumentTypes...) \
184+
__VA_ARGS__> \
185+
: FunctorTraitsImpl<ReturnType, \
186+
std::tuple<INSTANCE_TYPE*, ArgumentTypes...>, \
187+
1 + sizeof...(ArgumentTypes)> { \
188+
template <typename Functor, \
189+
std::size_t... Indexes, \
190+
typename BoundArgumentsTupleType, \
191+
typename... RunArgumentTypes> \
192+
static constexpr decltype(auto) Invoke( \
193+
Functor&& functor, \
194+
std::index_sequence<Indexes...>, \
195+
BoundArgumentsTupleType&& bound_arguments, \
196+
RunArgumentTypes&&... run_arguments) { \
197+
return MemberFunctionInvoke( \
198+
std::forward<Functor>( \
199+
functor), /* NOLINTBEGIN(bugprone-use-after-move) */ \
200+
std::get<Indexes>(std::forward<BoundArgumentsTupleType>( \
201+
bound_arguments))..., /* NOLINTEND(bugprone-use-after-move) */ \
202+
std::forward<RunArgumentTypes>(run_arguments)...); \
203+
} \
201204
}
202205

203206
LIBBASE_IMPL_MEMBER_FUNCTION_TRAIT(ClassType, );
@@ -243,8 +246,10 @@ struct FunctorTraits<OnceCallback<ReturnType(ArgumentTypes...)>>
243246
BoundArgumentsTupleType&& bound_arguments,
244247
RunArgumentTypes&&... run_arguments) {
245248
return std::forward<Functor>(functor).Run(
249+
// NOLINTBEGIN(bugprone-use-after-move)
246250
std::get<Indexes>(
247251
std::forward<BoundArgumentsTupleType>(bound_arguments))...,
252+
// NOLINTEND(bugprone-use-after-move)
248253
std::forward<RunArgumentTypes>(run_arguments)...);
249254
}
250255
};

src/base/message_loop/win/win_message_loop_attachment.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ namespace base {
1212
namespace win {
1313

1414
namespace {
15-
inline static const UINT WM_LIBBASE_EXECUTE_TASK = WM_USER + 0;
16-
inline static const wchar_t LIBBASE_CLASS_NAME[] = L"libbaseMessageOnlyWindow";
15+
inline const UINT WM_LIBBASE_EXECUTE_TASK = WM_USER + 0;
16+
inline const wchar_t LIBBASE_CLASS_NAME[] = L"libbaseMessageOnlyWindow";
1717

1818
thread_local WinMessageLoopAttachment* g_current_instance = nullptr;
1919

@@ -29,7 +29,7 @@ HWND CreateMessageOnlyWindow(WNDPROC wndProc) {
2929
WNDCLASS window_class = {};
3030
window_class.lpfnWndProc = wndProc;
3131
window_class.lpszClassName = LIBBASE_CLASS_NAME;
32-
window_class.hInstance = NULL; // hModule;
32+
window_class.hInstance = nullptr; // hModule;
3333
window_class.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1);
3434
RegisterClass(&window_class);
3535

@@ -70,7 +70,7 @@ class WinMessagePumpImpl : public MessagePumpImpl {
7070
// static
7171
std::unique_ptr<WinMessageLoopAttachment>
7272
WinMessageLoopAttachment::TryCreate() {
73-
if (auto hWnd =
73+
if (auto* hWnd =
7474
CreateMessageOnlyWindow(&WinMessageLoopAttachment::WindowProc)) {
7575
return std::unique_ptr<WinMessageLoopAttachment>(
7676
new WinMessageLoopAttachment(hWnd));

src/base/net/impl/net_thread_impl.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,11 @@ void NetThread::NetThreadImpl::EnqueueDownload_NetThread(
303303
auto [iter, inserted] =
304304
active_downloads_.emplace(easy_handle, std::move(download_info));
305305
DCHECK(inserted);
306-
const auto& inserted_info = iter->second;
306+
auto& inserted_info = iter->second;
307307

308308
// WARNING: Lambda has to be converted to function pointer or it will crash!
309-
curl_easy_setopt(easy_handle, CURLOPT_WRITEDATA, (void*)(&inserted_info));
309+
curl_easy_setopt(easy_handle, CURLOPT_WRITEDATA,
310+
static_cast<void*>(&inserted_info));
310311
curl_easy_setopt(
311312
easy_handle, CURLOPT_WRITEFUNCTION,
312313
+[](char* data, size_t n, size_t l, void* userp) -> size_t {

src/base/net/url_request.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class UrlRequest {
1818
public:
1919
class Client {
2020
public:
21+
virtual ~Client() = default;
2122
virtual void OnResponseStarted(
2223
const UrlRequest* request,
2324
int code,

0 commit comments

Comments
 (0)