[vte] cell: Silence an incorrect warning



commit 089b7964997123917f07c5d82bae301ac7364f6a
Author: Christian Persch <chpe src gnome org>
Date:   Fri Sep 28 12:17:40 2018 +0200

    cell: Silence an incorrect warning
    
    Compiling cell.hh with clang generates lots of warnings of the form:
    
    ./cell.hh:102:9: warning: taking address of packed member 'm_colors'
    of class or structure 'VteCellAttr' may result in an unaligned pointer
    value [-Waddress-of-packed-member]
            CELL_ATTR_COLOR(fore)
            ^~~~~~~~~~~~~~~~~~~~~
    ./cell.hh:94:46: note: expanded from macro 'CELL_ATTR_COLOR'
                    vte_color_triple_set_##name(&m_colors, value); \
                                                 ^~~~~~~~
    
    However, VteCellAttr is only ever used as a member of VteCell,
    where it has offset 4, resulting in the pointers being aligned
    sufficiently.

 src/cell.hh | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
---
diff --git a/src/cell.hh b/src/cell.hh
index db2042d0..06960862 100644
--- a/src/cell.hh
+++ b/src/cell.hh
@@ -21,6 +21,17 @@
 
 #pragma once
 
+#ifdef __clang__
+/* Clang generates lots of warnings for the code below. However while
+ * the pointer in the VteCellAttr struct is indeed only 4-byte aligned,
+ * the VteCellAttr is only used when a member of a VteCell, where it is
+ * at offset 4, resulting in a sufficient overall alignment. So we can
+ * safely ignore the warning.
+ */
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Waddress-of-packed-member"
+#endif /* __clang__ */
+
 #include <string.h>
 
 #include "vteunistr.h"
@@ -185,3 +196,7 @@ static const VteCell basic_cell = {
                 0, /* hyperlink_idx */
        }
 };
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]