From 3fb5cf3541c745b1a655f78ae593e665d4c4b6eb Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 22 Aug 2019 16:55:42 +0200 Subject: [PATCH] Using offsetof() when available in C++11. Avoids Clang sanitizer complaining about old-style macros. (#94) --- docs/CHANGELOG.txt | 1 + imgui.cpp | 2 +- imgui.h | 6 +++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 63033042..e5dfa657 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -39,6 +39,7 @@ Other Changes: when enabled will have small overlap glitches with (style.Alpha < 1.0). - TabBar: fixed ScrollToBar request creating bouncing loop when tab is larger than available space. - TabBar: fixed single-tab not shrinking their width down. +- Using offsetof() when available in C++11. Avoids Clang sanitizer complaining about old-style macros. (#94) - Backends: DX11: Fixed GSGetShader() call not passing an initialized instance count, would generally make the debug layer complain (Added in 1.72). - Backends: Vulkan: Added support for specifying multisample count. diff --git a/imgui.cpp b/imgui.cpp index 6be7fdc9..b4b4bc34 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -176,7 +176,7 @@ CODE - When using Dear ImGui, your programming IDE is your friend: follow the declaration of variables, functions and types to find comments about them. - Dear ImGui never touches or knows about your GPU state. The only function that knows about GPU is the draw function that you provide. Effectively it means you can create widgets at any time in your code, regardless of considerations of being in "update" vs "render" - phases of your own application. All rendering informatioe are stored into command-lists that you will retrieve after calling ImGui::Render(). + phases of your own application. All rendering information are stored into command-lists that you will retrieve after calling ImGui::Render(). - Refer to the bindings and demo applications in the examples/ folder for instruction on how to setup your code. - If you are running over a standard OS with a common graphics API, you should be able to use unmodified imgui_impl_*** files from the examples/ folder. diff --git a/imgui.h b/imgui.h index f5810519..abb42a78 100644 --- a/imgui.h +++ b/imgui.h @@ -73,8 +73,12 @@ Index of this file: #define IM_FMTLIST(FMT) #endif #define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR))) // Size of a static C-style array. Don't use on pointers! -#define IM_OFFSETOF(_TYPE,_MEMBER) ((size_t)&(((_TYPE*)0)->_MEMBER)) // Offset of _MEMBER within _TYPE. Standardized as offsetof() in modern C++. #define IM_UNUSED(_VAR) ((void)_VAR) // Used to silence "unused variable warnings". Often useful as asserts may be stripped out from final builds. +#if (__cplusplus >= 201100) +#define IM_OFFSETOF(_TYPE,_MEMBER) offsetof(_TYPE, _MEMBER) // Offset of _MEMBER within _TYPE. Standardized as offsetof() in C++11 +#else +#define IM_OFFSETOF(_TYPE,_MEMBER) ((size_t)&(((_TYPE*)0)->_MEMBER)) // Offset of _MEMBER within _TYPE. Old style macro. +#endif // Warnings #if defined(__clang__)