Fixed GCC mem-access warnings (#2565)
+ using "if defined" more consistently for Clang.
diff --git a/imgui.cpp b/imgui.cpp
index 66a4008..5334a35 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -995,7 +995,7 @@
#endif
// Clang/GCC warnings with -Weverything
-#ifdef __clang__
+#if defined(__clang__)
#pragma clang diagnostic ignored "-Wunknown-pragmas" // warning : unknown warning group '-Wformat-pedantic *' // not all warnings are known by all clang versions.. so ignoring warnings triggers new warnings on some configuration. great!
#pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
#pragma clang diagnostic ignored "-Wfloat-equal" // warning : comparing floating point with == or != is unsafe // storing and comparing against same constants (typically 0.0f) is ok.
diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index 7ce699d..1bc4a24 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -63,7 +63,7 @@
#ifdef _MSC_VER
#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
#endif
-#ifdef __clang__
+#if defined(__clang__)
#pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
#pragma clang diagnostic ignored "-Wdeprecated-declarations" // warning : 'xx' is deprecated: The POSIX name for this item.. // for strdup used in demo code (so user can copy & paste the code)
#pragma clang diagnostic ignored "-Wint-to-void-pointer-cast" // warning : cast to 'void *' from smaller integer type 'int'
diff --git a/imgui_draw.cpp b/imgui_draw.cpp
index c352db0..bcea633 100644
--- a/imgui_draw.cpp
+++ b/imgui_draw.cpp
@@ -52,7 +52,7 @@
#endif
// Clang/GCC warnings with -Weverything
-#ifdef __clang__
+#if defined(__clang__)
#pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
#pragma clang diagnostic ignored "-Wfloat-equal" // warning : comparing floating point with == or != is unsafe // storing and comparing against same constants ok.
#pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference is.
@@ -100,7 +100,7 @@
#pragma warning (disable: 4456) // declaration of 'xx' hides previous local declaration
#endif
-#ifdef __clang__
+#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-function"
#pragma clang diagnostic ignored "-Wmissing-prototypes"
@@ -108,7 +108,7 @@
#pragma clang diagnostic ignored "-Wcast-qual" // warning : cast from 'const xxxx *' to 'xxx *' drops const qualifier //
#endif
-#ifdef __GNUC__
+#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits" // warning: comparison is always true due to limited range of data type [-Wtype-limits]
#pragma GCC diagnostic ignored "-Wcast-qual" // warning: cast from type 'const xxxx *' to type 'xxxx *' casts away qualifiers
@@ -151,15 +151,15 @@
#endif
#endif
-#ifdef __GNUC__
+#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
-#ifdef __clang__
+#if defined(__clang__)
#pragma clang diagnostic pop
#endif
-#ifdef _MSC_VER
+#if defined(_MSC_VER)
#pragma warning (pop)
#endif
diff --git a/imgui_internal.h b/imgui_internal.h
index a44e566..8c4ef1d 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -36,15 +36,17 @@
#include <math.h> // sqrtf, fabsf, fmodf, powf, floorf, ceilf, cosf, sinf
#include <limits.h> // INT_MIN, INT_MAX
+// Visual Studio warnings
#ifdef _MSC_VER
#pragma warning (push)
#pragma warning (disable: 4251) // class 'xxx' needs to have dll-interface to be used by clients of struct 'xxx' // when IMGUI_API is set to__declspec(dllexport)
#endif
-#ifdef __clang__
+// Clang/GCC warnings with -Weverything
+#if defined(__clang__)
#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunused-function" // for stb_textedit.h
-#pragma clang diagnostic ignored "-Wmissing-prototypes" // for stb_textedit.h
+#pragma clang diagnostic ignored "-Wunused-function" // for stb_textedit.h
+#pragma clang diagnostic ignored "-Wmissing-prototypes" // for stb_textedit.h
#pragma clang diagnostic ignored "-Wold-style-cast"
#if __has_warning("-Wzero-as-null-pointer-constant")
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
@@ -52,6 +54,11 @@
#if __has_warning("-Wdouble-promotion")
#pragma clang diagnostic ignored "-Wdouble-promotion"
#endif
+#elif defined(__GNUC__)
+#pragma GCC diagnostic push
+#if __GNUC__ >= 8
+#pragma GCC diagnostic ignored "-Wclass-memaccess" // warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead
+#endif
#endif
//-----------------------------------------------------------------------------
@@ -1645,8 +1652,10 @@
#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID, _LABEL, _FLAGS) do { } while (0)
#endif
-#ifdef __clang__
+#if defined(__clang__)
#pragma clang diagnostic pop
+#elif defined(__GNUC__)
+#pragma GCC diagnostic pop
#endif
#ifdef _MSC_VER
diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp
index d34f519..8b05f77 100644
--- a/imgui_widgets.cpp
+++ b/imgui_widgets.cpp
@@ -51,7 +51,7 @@
#endif
// Clang/GCC warnings with -Weverything
-#ifdef __clang__
+#if defined(__clang__)
#pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
#pragma clang diagnostic ignored "-Wfloat-equal" // warning : comparing floating point with == or != is unsafe // storing and comparing against same constants (typically 0.0f) is ok.
#pragma clang diagnostic ignored "-Wformat-nonliteral" // warning : format string is not a string literal // passing non-literal to vsnformat(). yes, user passing incorrect format strings can crash the code.