浏览代码

Fixed ImVec2 operator[] violating aliasing rules causing issue with Intel C++ compiler. (#6272)

Note that this is not BayesBug's exact intended solution, so issues would be my responsibility ;)
Amended.
ocornut 2 年之前
父节点
当前提交
a38e3c222f
共有 2 个文件被更改,包括 4 次插入2 次删除
  1. 2 0
      docs/CHANGELOG.txt
  2. 2 2
      imgui.h

+ 2 - 0
docs/CHANGELOG.txt

@@ -54,6 +54,8 @@ Other changes:
 - ColorEdit: Fixed shading of S/V triangle in Hue Wheel mode. (#5200, #6254) [@jamesthomasgriffin]
 - ColorEdit: Fixed shading of S/V triangle in Hue Wheel mode. (#5200, #6254) [@jamesthomasgriffin]
 - Rendering: Using adaptative tesselation for: RadioButton, ColorEdit preview circles,
 - Rendering: Using adaptative tesselation for: RadioButton, ColorEdit preview circles,
   Windows Close and Collapse Buttons.
   Windows Close and Collapse Buttons.
+- Misc: Fixed ImVec2 operator[] violating aliasing rules causing issue with Intel C++
+  compiler. (#6272) [@BayesBug]
 - IO: Fixed support for calling io.AddXXXX functions fron inactive context (wrongly
 - IO: Fixed support for calling io.AddXXXX functions fron inactive context (wrongly
   advertised as supported in 1.89.4). (#6199, #6256, #5856) [@cfillion]
   advertised as supported in 1.89.4). (#6199, #6256, #5856) [@cfillion]
 - Backends: OpenGL3: Fixed GL loader crash when GL_VERSION returns NULL. (#6154, #4445, #3530)
 - Backends: OpenGL3: Fixed GL loader crash when GL_VERSION returns NULL. (#6154, #4445, #3530)

+ 2 - 2
imgui.h

@@ -255,8 +255,8 @@ struct ImVec2
     float                                   x, y;
     float                                   x, y;
     constexpr ImVec2()                      : x(0.0f), y(0.0f) { }
     constexpr ImVec2()                      : x(0.0f), y(0.0f) { }
     constexpr ImVec2(float _x, float _y)    : x(_x), y(_y) { }
     constexpr ImVec2(float _x, float _y)    : x(_x), y(_y) { }
-    float  operator[] (size_t idx) const    { IM_ASSERT(idx == 0 || idx == 1); return (&x)[idx]; }  // We very rarely use this [] operator, the assert overhead is fine.
-    float& operator[] (size_t idx)          { IM_ASSERT(idx == 0 || idx == 1); return (&x)[idx]; }  // We very rarely use this [] operator, the assert overhead is fine.
+    float& operator[] (size_t idx)          { IM_ASSERT(idx == 0 || idx == 1); return ((float*)(char*)this)[idx]; } // We very rarely use this [] operator, so the assert overhead is fine.
+    float  operator[] (size_t idx) const    { IM_ASSERT(idx == 0 || idx == 1); return ((const float*)(const char*)this)[idx]; }
 #ifdef IM_VEC2_CLASS_EXTRA
 #ifdef IM_VEC2_CLASS_EXTRA
     IM_VEC2_CLASS_EXTRA     // Define additional constructors and implicit cast operators in imconfig.h to convert back and forth between your math types and ImVec2.
     IM_VEC2_CLASS_EXTRA     // Define additional constructors and implicit cast operators in imconfig.h to convert back and forth between your math types and ImVec2.
 #endif
 #endif