[Bug c++/50012] [4.5/4.6/4.7 Regression] C++ front end misses -Wsign-compare warnings when extraneous parentheses are present

mikpe at it dot uu.se gcc-bugzilla@gcc.gnu.org
Sun Aug 14 12:43:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50012

--- Comment #2 from Mikael Pettersson <mikpe at it dot uu.se> 2011-08-14 12:25:12 UTC ---
The warning is lost due to this fragment of r148952 (with the rest of r148952
disabled):

--- gcc/cp/typeck.c    (revision 148951)
+++ gcc/cp/typeck.c    (revision 148952)
@@ -4018,6 +4018,8 @@ cp_build_binary_op (location_t location,

       if ((short_compare || code == MIN_EXPR || code == MAX_EXPR)
       && warn_sign_compare
+      && !TREE_NO_WARNING (orig_op0)
+      && !TREE_NO_WARNING (orig_op1)
       /* Do not warn until the template is instantiated; we cannot
          bound the ranges of the arguments until that point.  */
       && !processing_template_decl

In this test case (the foo() function) the LHS is a parenthesized expression,
and cp/semantics.c:finish_parenthesized_expr() contains the following gem:

tree
finish_parenthesized_expr (tree expr)
{
  if (EXPR_P (expr))
    /* This inhibits warnings in c_common_truthvalue_conversion.  */
    TREE_NO_WARNING (expr) = 1;

Disabling either the setting of TREE_NO_WARNING in finish_parenthesized_expr or
the && !TREE_NO_WARNING check in cp_build_binary_op restores the warning for
this test case.  Alas I'm sure something else will break in that case ...



More information about the Gcc-bugs mailing list