[glibmm] Glib::Binding: Avoid warning from gcc-10



commit 12b5837128ab022a26f324e3476ccc7ede51e9b5
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Tue Dec 8 15:04:34 2020 +0100

    Glib::Binding: Avoid warning from gcc-10
    
    g++-10 with optimization level -O1 or higher warns about possible use of
    an uninitialized variable when tests/glibmm_binding/main.cc is compiled.
    I don't understand why.
    
    There is no warning if the private method Glib::Binding::TransformProp::
    operator()() is compiled without optimization. Add an attribute that turns
    off optimization for this method when it's compiled with with gcc-10 or
    higher. gcc-9 does not warn. gcc-10 does not warn in glibmm-2.4, where
    std::optional is not used.

 glib/src/binding.hg | 9 +++++++++
 1 file changed, 9 insertions(+)
---
diff --git a/glib/src/binding.hg b/glib/src/binding.hg
index 52bbbdb6..73451ba4 100644
--- a/glib/src/binding.hg
+++ b/glib/src/binding.hg
@@ -417,6 +417,15 @@ private:
   public:
     explicit TransformProp(const SlotTypedTransform<T_from, T_to>& slot) : typed_transform(slot) {}
 
+    // g++-10 with optimization level -O1 or higher warns about possible use of
+    // an uninitialized variable when tests/glibmm_binding/main.cc is compiled.
+    // I don't understand why. Don't optimize this function. /Kjell 2020-12-08
+    //   sigc++-3.0/sigc++/functors/slot.h:226:21: warning: ‘<anonymous>’ may be
+    //   used uninitialized in this function [-Wmaybe-uninitialized]
+    //   226 |     return T_return();
+#if __GNUC__ >= 10
+  __attribute__ ((optimize(0)))
+#endif
     bool operator()(const GValue* from_value, GValue* to_value)
     {
       Glib::Value<T_from> from_glib_value;


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