Skip to content

Commit 32b0bb2

Browse files
authored
Fix warnings when upgraded to clang 22 (#415)
1 parent 95251b3 commit 32b0bb2

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ if(MSVC)
494494

495495
if(NO_WCHAR_T)
496496
message(STATUS "Using non-native wchar_t as unsigned short")
497-
target_compile_options(${PROJECT_NAME} PRIVATE "/Zc:wchar_t-")
497+
target_compile_options(${PROJECT_NAME} PRIVATE /Zc:wchar_t-)
498498
endif()
499499
endif()
500500

@@ -505,14 +505,14 @@ target_link_options(${PROJECT_NAME} PRIVATE ${LINKER_SWITCHES})
505505
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|IntelLLVM")
506506
set(WarningsLib -Wall -Wpedantic -Wextra)
507507
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0)
508-
list(APPEND WarningsLib "-Wno-unsafe-buffer-usage")
508+
list(APPEND WarningsLib -Wno-unsafe-buffer-usage)
509509
endif()
510510
target_compile_options(${PROJECT_NAME} PRIVATE ${WarningsLib})
511511
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
512-
target_compile_options(${PROJECT_NAME} PRIVATE "-Wno-ignored-attributes" "-Walloc-size-larger-than=4GB")
512+
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-ignored-attributes -Walloc-size-larger-than=4GB)
513513

514514
if(BUILD_SHARED_LIBS)
515-
target_compile_options(${PROJECT_NAME} PRIVATE "-Wno-attributes")
515+
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-attributes)
516516
endif()
517517
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
518518
if(BUILD_SHARED_LIBS)

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
@@ -78,6 +78,7 @@
7878
#pragma clang diagnostic ignored "-Wlanguage-extension-token"
7979
#pragma clang diagnostic ignored "-Wmissing-variable-declarations"
8080
#pragma clang diagnostic ignored "-Wnested-anon-types"
81+
#pragma clang diagnostic ignored "-Wpadded"
8182
#pragma clang diagnostic ignored "-Wreserved-id-macro"
8283
#pragma clang diagnostic ignored "-Wswitch-enum"
8384
#pragma clang diagnostic ignored "-Wunknown-pragmas"

0 commit comments

Comments
 (0)