Another braces warning this that I overlooked

Guido Lerch guido.lerch at gmail.com
Thu Oct 22 04:29:46 PDT 2015


Hi Dirk

Thanks, I got a warning about dangling braces. That is send in two patches was because I didn't capture the second set the first time and I am still having issues to understand GIT  reset --amend and so on... GIT commands never get me where I think they would.

I'd love to see what you do when you rewrite my patches..
Are you doing this in a editor or do you apply them to a branch, reset the head and then commit?

Regards,
Guido
+41 79 3217739

> Am 22.10.2015 um 12:38 schrieb Dirk Hohndel <dirk at hohndel.org>:
> 
>> On Thu, Oct 22, 2015 at 09:21:41AM +0200, Robert C. Helling wrote:
>> Dirk,
>> 
>>> On 22 Oct 2015, at 09:15, Dirk Hohndel <dirk at hohndel.org> wrote:
>>> 
>>> Why? What does the compiler complain about? The existing code is correct
>>> and unambiguous. What am I missing?
>> 
>> one could worry to which if the else applies (yes, there is a rule but people often get this wrong. And since this is not python the compiler does not look at your beautiful indentation).
> 
> Yes. It is well defined, and clear to the reader, but still, in theory one
> could misinterpret it. In practice C binds else to the closest if, so the
> code is actually correct.
> 
> I will once again rewrite Guido's patches into one simpler one that makes
> it unambiguous... basically the second patch without the first :-)
> 
> /D
> 
> commit f1c682b55a52c11d7cb57da0fc66d6edb118ba77
> Author: Guido Lerch <guido.lerch at gmail.com>
> Date:   Thu Oct 22 00:17:05 2015 +0200
> 
>    Fixing annoying compiler warning
> 
>    Adding { } to if clause to avoid dangling warning
>    /Users/guidolerch/src/subsurface/qt-models/cylindermodel.cpp:117:
>    warning: add explicit braces to avoid dangling else [-Wdangling-else]
> 
>    [Dirk Hohndel: combined two of Guido's patches to one that is simpler]
> 
>    Signed-off-by: Guido Lerch <guido.lerch at gmail.com>
>    Signed-off-by: Dirk Hohndel <dirk at hohndel.org>
> 
> diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp
> index 8c9bee8b1882..8341d36081eb 100644
> --- a/qt-models/cylindermodel.cpp
> +++ b/qt-models/cylindermodel.cpp
> @@ -111,18 +111,20 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
>        }
>        break;
>    case Qt::DecorationRole:
> -        if (index.column() == REMOVE)
> +        if (index.column() == REMOVE) {
>            if (rowCount() > 1)
>                ret = trashIcon();
>            else
>                ret = trashForbiddenIcon();
> +        }
>        break;
>    case Qt::SizeHintRole:
> -        if (index.column() == REMOVE)
> +        if (index.column() == REMOVE) {
>            if (rowCount() > 1)
>                ret = trashIcon();
>            else
>                ret = trashForbiddenIcon();
> +        }
>        break;
> 
>    case Qt::ToolTipRole:
> 


More information about the subsurface mailing list