[Libreoffice-commits] bogus WaE: 'bValue' may be used uninitialized in this function

Stephan Bergmann sbergman at redhat.com
Thu Oct 17 15:27:10 CEST 2013


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 at 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;


More information about the LibreOffice mailing list