Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


In cases like the below, I usually settle on the compromise of explicitly value-initializing the variable v of (fundamental) type T with

  T v = T();

(maybe even adding a comment like "// avoid warnings"), which keeps compilers happy but still makes it clear to the reader not to assume v is deliberately assigned a specific value at that point, which is the problem with a hack like

  bool bValue = false;

Stephan

On 10/17/2013 04:07 AM, Lionel Elie Mamane wrote:
commit 9d5e05edb20819e7b989f366fbd86ca4c2cd7cc5
Author: Lionel Elie Mamane <lionel@mamane.lu>
Date:   Thu Oct 17 04:06:24 2013 +0200

     bogus WaE: 'bValue' may be used uninitialized in this function

     Change-Id: I14983509a41bd6be0d7fed29d7f89fa4a21fe08a

diff --git a/forms/source/component/CheckBox.cxx b/forms/source/component/CheckBox.cxx
index 5198ccc..5db7397 100644
--- a/forms/source/component/CheckBox.cxx
+++ b/forms/source/component/CheckBox.cxx
@@ -217,7 +217,7 @@ Any OCheckBoxModel::translateDbColumnToControlValue()

      //////////////////////////////////////////////////////////////////
      // Set value in ControlModel
-    bool bValue = false;
+    bool bValue;
      if(DbUseBool())
      {
          bValue = m_xColumn->getBoolean();
@@ -241,7 +241,17 @@ Any OCheckBoxModel::translateDbColumnToControlValue()
      }
      else if ( !aValue.hasValue() )
      {
+        // Since above either bValue is initialised, either aValue.hasValue(),
+        // bValue cannot be used uninitialised here.
+        // But GCC does not see/understand that, which breaks -Werror builds.
+#if defined __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
          aValue <<= (sal_Int16)( bValue ? STATE_CHECK : STATE_NOCHECK );
+#if defined __GNUC__
+#pragma GCC diagnostic pop
+#endif
      }

      return aValue;

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.