From 1633d3b91af987aefd53b64cd4071923e1f45502 Mon Sep 17 00:00:00 2001
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date: Mon, 3 Oct 2016 08:00:21 +0000
Subject: [PATCH] invoke.texi: Update -Wint-in-bool-context.

2016-10-03  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        * doc/invoke.texi: Update -Wint-in-bool-context.

c-family:
2016-10-03  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        * c-common.c (c_common_truthvalue_conversion): Warn for suspicious
        left shift in boolean context.

cp:
2016-10-03  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        * parser.c (cp_parser_condition): Fix a warning.

testsuite:
2016-10-03  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        * c-c++-common/Wint-in-bool-context.c: Update test.

From-SVN: r240706
---
 gcc/ChangeLog                                     |  4 ++++
 gcc/c-family/ChangeLog                            |  5 +++++
 gcc/c-family/c-common.c                           | 11 +++++++++++
 gcc/cp/ChangeLog                                  |  4 ++++
 gcc/cp/parser.c                                   |  2 +-
 gcc/doc/invoke.texi                               |  3 ++-
 gcc/testsuite/ChangeLog                           |  4 ++++
 gcc/testsuite/c-c++-common/Wint-in-bool-context.c |  2 ++
 8 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 05e527d406b5..f485096e7681 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,7 @@
+2016-10-03  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+	* doc/invoke.texi: Update -Wint-in-bool-context.
+
 2016-10-02  Jakub Jelinek  <jakub@redhat.com>
 
 	* dwarf2out.c (output_fde, output_call_frame_info,
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 3e606940d132..6c2f3cf5655b 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,8 @@
+2016-10-03  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+	* c-common.c (c_common_truthvalue_conversion): Warn for suspicious
+	left shift in boolean context.
+
 2016-09-29  Jakub Jelinek  <jakub@redhat.com>
 
 	Implement P0001R1 - C++17 removal of register storage class specifier
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 2652259a312d..491c637b5605 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -4655,6 +4655,11 @@ c_common_truthvalue_conversion (location_t location, tree expr)
 	return c_common_truthvalue_conversion (location,
 					       TREE_OPERAND (expr, 0));
 
+    case LSHIFT_EXPR:
+      warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
+		  "<< in boolean context, did you mean '<' ?");
+      break;
+
     case COND_EXPR:
       if (warn_int_in_bool_context
 	  && !from_macro_definition_at (EXPR_LOCATION (expr)))
@@ -4676,6 +4681,8 @@ c_common_truthvalue_conversion (location_t location, tree expr)
 	{
 	  tree op1 = TREE_OPERAND (expr, 1);
 	  tree op2 = TREE_OPERAND (expr, 2);
+	  int w = warn_int_in_bool_context;
+	  warn_int_in_bool_context = 0;
 	  /* In C++ one of the arms might have void type if it is throw.  */
 	  if (!VOID_TYPE_P (TREE_TYPE (op1)))
 	    op1 = c_common_truthvalue_conversion (location, op1);
@@ -4683,10 +4690,13 @@ c_common_truthvalue_conversion (location_t location, tree expr)
 	    op2 = c_common_truthvalue_conversion (location, op2);
 	  expr = fold_build3_loc (location, COND_EXPR, truthvalue_type_node,
 				  TREE_OPERAND (expr, 0), op1, op2);
+	  warn_int_in_bool_context = w;
 	  goto ret;
 	}
       else
 	{
+	  int w = warn_int_in_bool_context;
+	  warn_int_in_bool_context = 0;
 	  /* Folding will happen later for C.  */
 	  expr = build3 (COND_EXPR, truthvalue_type_node,
 			 TREE_OPERAND (expr, 0),
@@ -4694,6 +4704,7 @@ c_common_truthvalue_conversion (location_t location, tree expr)
 							 TREE_OPERAND (expr, 1)),
 			 c_common_truthvalue_conversion (location,
 							 TREE_OPERAND (expr, 2)));
+	  warn_int_in_bool_context = w;
 	  goto ret;
 	}
 
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index fb0c0e0ffaa7..595624c2e298 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,7 @@
+2016-10-03  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+	* parser.c (cp_parser_condition): Fix a warning.
+
 2016-09-29  Jakub Jelinek  <jakub@redhat.com>
 
 	Implement P0001R1 - C++17 removal of register storage class specifier
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index f672b8de1885..16b895cf37a8 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -11244,7 +11244,7 @@ cp_parser_condition (cp_parser* parser)
 	{
 	  tree pushed_scope;
 	  bool non_constant_p;
-	  bool flags = LOOKUP_ONLYCONVERTING;
+	  int flags = LOOKUP_ONLYCONVERTING;
 
 	  /* Create the declaration.  */
 	  decl = start_decl (declarator, &type_specifiers,
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index fa1552988e37..d9667e7f5d91 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -6038,7 +6038,8 @@ of the C++ standard.
 @opindex Wno-int-in-bool-context
 Warn for suspicious use of integer values where boolean values are expected,
 such as conditional expressions (?:) using non-boolean integer constants in
-boolean context, like @code{if (a <= b ? 2 : 3)}.
+boolean context, like @code{if (a <= b ? 2 : 3)}.  Or left shifting in
+boolean context, like @code{for (a = 0; 1 << a; a++);}.
 This warning is enabled by @option{-Wall}.
 
 @item -Wno-int-to-pointer-cast
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 54de56f8f3c9..075ff714c523 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2016-10-03  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+	* c-c++-common/Wint-in-bool-context.c: Update test.
+
 2016-10-02  Jakub Jelinek  <jakub@redhat.com>
 
 	* g++.dg/ext/asm3.C (two): Only use register keyword for C++14 and
diff --git a/gcc/testsuite/c-c++-common/Wint-in-bool-context.c b/gcc/testsuite/c-c++-common/Wint-in-bool-context.c
index 38832d78f2f9..832eb0a0ee37 100644
--- a/gcc/testsuite/c-c++-common/Wint-in-bool-context.c
+++ b/gcc/testsuite/c-c++-common/Wint-in-bool-context.c
@@ -25,5 +25,7 @@ int foo (int a, int b)
   if (b ? 1+1 : 1) /* { dg-warning "boolean context" } */
     return 7;
 
+  for (a = 0; 1 << a; a++); /* { dg-warning "boolean context" } */
+
   return 0;
 }
-- 
GitLab