[C++ Patch] PR 53524

Paolo Carlini paolo.carlini@oracle.com
Mon Jun 4 18:52:00 GMT 2012


On 06/04/2012 08:24 PM, Jason Merrill wrote:
> On 06/04/2012 01:52 PM, Paolo Carlini wrote:
>> Ok, this would be simple to do. The only issue I can see, is that in C++
>> -Wenum-compare has a name, thus can be easily disabled but it's ON by
>> default.
> The warning is already on by default, so that wouldn't be a change; 
> this just creates a way for users to turn it off until we deal with 
> the unhelpful case.
Ok. The below passes the testsuite on x86_64-linux. Ok for mainline and 
4.7.1?

Thanks,
Paolo.

/////////////////////
-------------- next part --------------
2012-06-04  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53524
	* doc/invoke.texi (Wenum-compare): Update documentation.

/cp
2012-06-04  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53524
	* call.c (build_conditional_expr_1): Use OPT_Wenum_compare
	to control enumeral mismatch in conditional expression too.

/testsuite
2012-06-04  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53524
	* g++.dg/warn/Wenum-compare-no-2: New.
-------------- next part --------------
Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi	(revision 188196)
+++ doc/invoke.texi	(working copy)
@@ -4297,9 +4297,10 @@ while} statement.  This warning is also enabled by
 @item -Wenum-compare
 @opindex Wenum-compare
 @opindex Wno-enum-compare
-Warn about a comparison between values of different enumerated types. In C++
-this warning is enabled by default.  In C this warning is enabled by
-@option{-Wall}.
+Warn about a comparison between values of different enumerated types.
+In C++ enumeral mismatches in conditional expressions are also
+diagnosed and the warning is enabled by default.  In C this warning is 
+enabled by @option{-Wall}.
 
 @item -Wjump-misses-init @r{(C, Objective-C only)}
 @opindex Wjump-misses-init
Index: testsuite/g++.dg/warn/Wenum-compare-no-2.C
===================================================================
--- testsuite/g++.dg/warn/Wenum-compare-no-2.C	(revision 0)
+++ testsuite/g++.dg/warn/Wenum-compare-no-2.C	(revision 0)
@@ -0,0 +1,31 @@
+// PR c++/53524
+// { dg-options "-Wno-enum-compare" }
+
+template < typename > struct PointerLikeTypeTraits {
+  enum { NumLowBitsAvailable };
+};
+
+class CodeGenInstruction;
+class CodeGenInstAlias;
+
+template < typename T>
+struct PointerIntPair {
+  enum { IntShift = T::NumLowBitsAvailable };
+};
+
+template < typename PT1, typename PT2 > struct PointerUnionUIntTraits {
+  enum {
+    PT1BitsAv = PointerLikeTypeTraits < PT1 >::NumLowBitsAvailable,
+    PT2BitsAv = PointerLikeTypeTraits < PT2 >::NumLowBitsAvailable,
+    NumLowBitsAvailable = 0 ? PT1BitsAv : PT2BitsAv
+  };
+};
+
+template < typename PT1, typename PT2 > class PointerUnion {
+  typedef PointerIntPair < PointerUnionUIntTraits < PT1, PT2 > > ValTy;
+  ValTy Val;
+};
+
+struct ClassInfo {
+  PointerUnion < CodeGenInstruction *, CodeGenInstAlias * > DefRec;
+};
Index: testsuite/g++.dg/cpp0x/alias-decl-19.C
===================================================================
Index: cp/call.c
===================================================================
--- cp/call.c	(revision 188196)
+++ cp/call.c	(working copy)
@@ -4696,7 +4696,7 @@ build_conditional_expr_1 (tree arg1, tree arg2, tr
 	  && TREE_CODE (arg3_type) == ENUMERAL_TYPE)
         {
           if (complain & tf_warning)
-            warning (0, 
+            warning (OPT_Wenum_compare, 
                      "enumeral mismatch in conditional expression: %qT vs %qT",
                      arg2_type, arg3_type);
         }


More information about the Gcc-patches mailing list