Andre Poenitz wrote:
After revision 22857 gcc complains:

../../../../trunk/src/support/qstring_helpers.h: In function 'const
QString lyx::toqstr(lyx::char_type)':
../../../../trunk/src/support/qstring_helpers.h:75: warning:
dereferencing type-punned pointer will break strict-aliasing rules

Possible fix:

Index: qstring_helpers.h
===================================================================
--- qstring_helpers.h   (revision 22868)
+++ qstring_helpers.h   (working copy)
@@ -72,7 +72,8 @@
  */
 inline QString const toqstr(char_type ucs4)
 {
-       return QString::fromUcs4(reinterpret_cast<uint const *>(&ucs4), 1);
+       union { char_type c; uint i; } u = { ucs4 };
+       return QString::fromUcs4(&u.i, 1);

or simply:

+       return QString::fromUcs4((uint const *) (&ucs4), 1);

Which I am sure works. I never quite understood what this reinterpret_cast was useful for.

Abdel.

  • gcc warnings Andre Poenitz
    • Re: gcc warnings Abdelrazak Younes

Reply via email to