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

mpolacek at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed May 4 16:53:00 GMT 2016


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

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
This should fix it then:

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index d275f8e..d31e915 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -5532,7 +5532,7 @@ c_parser_if_statement (c_parser *parser, bool *if_p,
vec<tree> *chain)
       /* Set IF_P to true to indicate that this if statement has an
     else clause.  This may trigger the Wparentheses warning
     below when we get back up to the parent if statement.  */
-      if (if_p != NULL)
+      if (if_p != NULL && !from_macro_expansion_at (loc))
    *if_p = true;
     }
   else
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index da2ee3c..f6b8008 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -10848,6 +10848,7 @@ cp_parser_selection_statement (cp_parser* parser, bool
*if_p,
       {
    tree statement;
    tree condition;
+   location_t loc = cp_lexer_peek_token (parser->lexer)->location;

    /* Look for the `('.  */
    if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
@@ -10941,7 +10942,7 @@ cp_parser_selection_statement (cp_parser* parser, bool
*if_p,
           indicate that this if statement has an else clause.
           This may trigger the Wparentheses warning below
           when we get back up to the parent if statement.  */
-       if (if_p != NULL)
+       if (if_p != NULL && !from_macro_expansion_at (loc))
          *if_p = true;
          }
        else


More information about the Gcc-bugs mailing list