diff mbox series

[C++] Avoid duplicate warning

Message ID 1c19955c-f213-0c35-b2b8-93a9517c86dc@oracle.com
State New
Headers show
Series [C++] Avoid duplicate warning | expand

Commit Message

Paolo Carlini Nov. 18, 2019, 3:45 p.m. UTC
Hi,

functions like c_common_truthvalue_conversion are shared with the C 
front-end thus don't get a tsubst_flags_t argument. It seems clear that 
long term we have to do something about those but in the meanwhile we 
have been using warning sentinels which, along the paths which certainly 
must have all the warnings suppressed, work well for now and cannot 
cause regressions. Here I propose to add (at least) one more to 
ocp_convert since I have a straightforward testcase. Note sue if we want 
to proactively add, say, one for warn_parentheses too.

Tested x86_64-linux.

Thanks, Paolo.

///////////////////
/cp
2019-11-18  Paolo Carlini  <paolo.carlini@oracle.com>

	* cvt.c (ocp_convert): Use additional warning sentinel.

/testsuite
2019-11-18  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/warn/multiple-sign-compare-warn-1.C: New.

Comments

Jason Merrill Nov. 19, 2019, 10:36 p.m. UTC | #1
On 11/18/19 3:45 PM, Paolo Carlini wrote:

> functions like c_common_truthvalue_conversion are shared with the C 
> front-end thus don't get a tsubst_flags_t argument. It seems clear that 
> long term we have to do something about those but in the meanwhile we 
> have been using warning sentinels which, along the paths which certainly 
> must have all the warnings suppressed, work well for now and cannot 
> cause regressions. Here I propose to add (at least) one more to 
> ocp_convert since I have a straightforward testcase.

OK.

> Note sue if we want to proactively add, say, one for warn_parentheses too.

Not without a testcase.

Jason
diff mbox series

Patch

Index: cp/cvt.c
===================================================================
--- cp/cvt.c	(revision 278407)
+++ cp/cvt.c	(working copy)
@@ -847,6 +847,7 @@  ocp_convert (tree type, tree expr, int convtype, i
 	      /* Prevent bogus -Wint-in-bool-context warnings coming
 		 from c_common_truthvalue_conversion down the line.  */
 	      warning_sentinel w (warn_int_in_bool_context);
+	      warning_sentinel c (warn_sign_compare);
 	      return cp_truthvalue_conversion (e, complain);
 	    }
 	}
Index: testsuite/g++.dg/warn/multiple-sign-compare-warn-1.C
===================================================================
--- testsuite/g++.dg/warn/multiple-sign-compare-warn-1.C	(nonexistent)
+++ testsuite/g++.dg/warn/multiple-sign-compare-warn-1.C	(working copy)
@@ -0,0 +1,11 @@ 
+// { dg-options "-Wsign-compare" }
+
+int foo()
+{
+  unsigned char b = '1';
+
+  bool x = ~b; // { dg-bogus "promoted bitwise complement of an unsigned value is always nonzero.*promoted bitwise complement of an unsigned value is always nonzero" }
+ // { dg-warning "promoted bitwise complement of an unsigned value is always nonzero" "" { target *-*-* } .-1 }
+
+  return 0;
+}