From 6c00d1916e854d6605dd4474a188ad3393117504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Molinari?= Date: Sun, 29 Dec 2019 15:39:49 +0100 Subject: [PATCH] Disable format checks when using stb_sprintf.h STB sprintf allows extra formats like %b or %$d. If ImGui is configured to use STB sprintf, it generates warnings with GCC and clang when using such formats because it keeps applying default printf-style warnings. This commit disables printf-style warnings when using STB sprintf. Since the printf-style warnings are defined in imgui.h based on the compiler, IMGUI_USE_STB_SPRINTF can't just be defined in the cpp file anymore and it's been moved as a proper config in imconfig.h. --- docs/CHANGELOG.txt | 2 ++ imconfig.h | 4 ++++ imgui.cpp | 1 - imgui.h | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index ae1288532..11e4fdf03 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -75,6 +75,8 @@ Other Changes: we will rework the circle rendering functions to use textures and automatic segment count selection, those new api can fill a gap. [@ShironekoBen] - Misc: Added ImGuiMouseCursor_NotAllowed enum so it can be used by more shared widgets. [@rokups] +- Misc: Disable format checks when using stb_printf, to allow using extra formats. + Made IMGUI_USE_STB_SPRINTF a properly documented imconfig.h flag. (#2954) [@loicmolinari] - Misc: Added misc/single_file/imgui_single_file.h, We use this to validate compiling all *.cpp files in a same compilation unit. Actual users of that technique (also called "Unity builds") can generally provide this themselves, so we don't really recommend you use this. [@rokups] diff --git a/imconfig.h b/imconfig.h index c4f7891e6..6724e40fe 100644 --- a/imconfig.h +++ b/imconfig.h @@ -53,6 +53,10 @@ //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION +//---- Unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined, use the much faster STB sprintf library implementation of vsnprintf instead of the one from the default C library. +// Note that stb_sprintf.h is meant to be provided by the user and available in the include path at compile time. Also, the compatibility checks of the arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by STB sprintf. +// #define IMGUI_USE_STB_SPRINTF + //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. // This will be inlined as part of ImVec2 and ImVec4 class declarations. /* diff --git a/imgui.cpp b/imgui.cpp index a9e2dd7a5..09a315ccc 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1354,7 +1354,6 @@ const char* ImStrSkipBlank(const char* str) // You may set IMGUI_USE_STB_SPRINTF to use our default wrapper, or set IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // and setup the wrapper yourself. (FIXME-OPT: Some of our high-level operations such as ImGuiTextBuffer::appendfv() are // designed using two-passes worst case, which probably could be improved using the stbsp_vsprintfcb() function.) -//#define IMGUI_USE_STB_SPRINTF #ifdef IMGUI_USE_STB_SPRINTF #define STB_SPRINTF_IMPLEMENTATION #include "stb_sprintf.h" diff --git a/imgui.h b/imgui.h index c2cde0d21..1245ab1b1 100644 --- a/imgui.h +++ b/imgui.h @@ -76,7 +76,7 @@ Index of this file: #include #define IM_ASSERT(_EXPR) assert(_EXPR) // You can override the default assert handler by editing imconfig.h #endif -#if defined(__clang__) || defined(__GNUC__) +#if !defined(IMGUI_USE_STB_SPRINTF) && (defined(__clang__) || defined(__GNUC__)) #define IM_FMTARGS(FMT) __attribute__((format(printf, FMT, FMT+1))) // To apply printf-style warnings to our functions. #define IM_FMTLIST(FMT) __attribute__((format(printf, FMT, 0))) #else