This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/70922] -Wparentheses warning should not complain about if-else from macro expansion


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70922

--- Comment #15 from Manuel LÃpez-IbÃÃez <manu at gcc dot gnu.org> ---
Indeed, we also warn for

void bar(int x)
{
    if (x)
        for (int i = x; i < 5; i++) 
            if (i != 0)                                 
            {                                                                   
                /* Nothing.  */                                                 
            }                                                                   
            else
                if(!x)
                    return; 
}

Perhaps we should not warn if some other construct breaks the ambiguity (like
for, while, etc.). But I can see that one may wrongly write:

void bar(int x)
{
    if (x)
        MACRO_WITH_ELSE(x)
    if(!x)
       return; 
}

and not be aware that the macro changes the meaning of the following 'if'. The
extra braces may seem redundant, but they avoid such pitfalls:

void bar(int x)
{
    if (x)
    {
        MACRO_WITH_ELSE(x)
    if(!x)
       return; 
    }
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]