diff mbox

[C++] PR 53524

Message ID 4FCD0372.4050003@oracle.com
State New
Headers show

Commit Message

Paolo Carlini June 4, 2012, 6:50 p.m. UTC
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.

/////////////////////
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.

Comments

Jason Merrill June 4, 2012, 7:16 p.m. UTC | #1
On 06/04/2012 02:50 PM, Paolo Carlini wrote:
> Ok. The below passes the testsuite on x86_64-linux. Ok for mainline and
> 4.7.1?

OK.  But let's leave the bug open until we fix the warning not to 
complain about this testcase even with -Wenum-compare on.

Jason
Paolo Carlini June 4, 2012, 7:23 p.m. UTC | #2
On 06/04/2012 09:16 PM, Jason Merrill wrote:
> On 06/04/2012 02:50 PM, Paolo Carlini wrote:
>> Ok. The below passes the testsuite on x86_64-linux. Ok for mainline and
>> 4.7.1?
>
> OK.  But let's leave the bug open until we fix the warning not to 
> complain about this testcase even with -Wenum-compare on.
Sure.

Paolo.
diff mbox

Patch

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);
         }