Skip to content

Commit 9388b20

Browse files
authored
Fix warnings when ugpraded to clang 22 (#646)
1 parent 07c143e commit 9388b20

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ if(MSVC)
463463
if(NO_WCHAR_T)
464464
message(STATUS "Using non-native wchar_t as unsigned short")
465465
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
466-
target_compile_options(${t} PRIVATE "/Zc:wchar_t-")
466+
target_compile_options(${t} PRIVATE /Zc:wchar_t-)
467467
endforeach()
468468
endif()
469469
endif()
@@ -477,13 +477,14 @@ endforeach()
477477
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|IntelLLVM")
478478
set(WarningsLib -Wall -Wpedantic -Wextra)
479479
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0)
480-
list(APPEND WarningsLib "-Wno-unsafe-buffer-usage")
480+
list(APPEND WarningsLib -Wno-unsafe-buffer-usage)
481481
endif()
482482
target_compile_options(${PROJECT_NAME} PRIVATE ${WarningsLib})
483483

484-
set(WarningsEXE ${WarningsLib} "-Wno-c++98-compat" "-Wno-c++98-compat-pedantic" "-Wno-switch-default"
485-
"-Wno-double-promotion" "-Wno-exit-time-destructors" "-Wno-gnu-anonymous-struct"
486-
"-Wno-missing-prototypes" "-Wno-nested-anon-types" "-Wno-unused-const-variable")
484+
set(WarningsEXE ${WarningsLib}
485+
-Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-switch-default
486+
-Wno-double-promotion -Wno-exit-time-destructors -Wno-gnu-anonymous-struct
487+
-Wno-missing-prototypes -Wno-nested-anon-types -Wno-unused-const-variable -Wno-padded)
487488
foreach(t IN LISTS TOOL_EXES)
488489
target_compile_options(${t} PRIVATE ${WarningsEXE})
489490
endforeach()

Src/PlatformHelpers.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <cstdio>
1818
#include <exception>
1919
#include <memory>
20+
#include <string>
2021

2122
#ifndef MAKEFOURCC
2223
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
@@ -41,19 +42,23 @@ namespace DirectX
4142
class com_exception : public std::exception
4243
{
4344
public:
44-
com_exception(HRESULT hr) noexcept : result(hr) {}
45+
explicit com_exception(HRESULT hr) : result(hr)
46+
{
47+
char str[64] = {};
48+
sprintf_s(str, "Failure with HRESULT of %08X", static_cast<unsigned int>(result));
49+
message = str;
50+
}
4551

4652
const char* what() const noexcept override
4753
{
48-
static char s_str[64] = {};
49-
sprintf_s(s_str, "Failure with HRESULT of %08X", static_cast<unsigned int>(result));
50-
return s_str;
54+
return message.c_str();
5155
}
5256

5357
HRESULT get_result() const noexcept { return result; }
5458

5559
private:
5660
HRESULT result;
61+
std::string message;
5762
};
5863

5964
// Helper utility converts D3D API failures into exceptions.

Src/pch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#pragma clang diagnostic ignored "-Wmissing-variable-declarations"
7878
#pragma clang diagnostic ignored "-Wmicrosoft-include"
7979
#pragma clang diagnostic ignored "-Wnested-anon-types"
80+
#pragma clang diagnostic ignored "-Wpadded"
8081
#pragma clang diagnostic ignored "-Wreserved-id-macro"
8182
#pragma clang diagnostic ignored "-Wswitch-enum"
8283
#pragma clang diagnostic ignored "-Wunknown-pragmas"

0 commit comments

Comments
 (0)