[C++ Patch] PR 60978

2014-12-02 Thread Paolo Carlini

Hi,

another simple issue: this one argues that the warning is overeager when 
anonymous enums are involved, which often are just used as named 
constants. Details: maybe write the conditional in a different way; 
maybe even use  instead of ||. Tested x86_64-linux.


Thanks,
Paolo.

//
/cp
2014-12-02  Paolo Carlini  paolo.carl...@oracle.com

PR c++/60978
* call.c (build_conditional_expr_1): Do not -Wenum-compare warn
for anonymous enums.

/testsuite
2014-12-02  Paolo Carlini  paolo.carl...@oracle.com

PR c++/60978
* g++.dg/warn/Wenum-compare-2.C: New.
Index: cp/call.c
===
--- cp/call.c   (revision 218278)
+++ cp/call.c   (working copy)
@@ -5014,6 +5014,10 @@ build_conditional_expr_1 (location_t loc, tree arg
   DECL_CONTEXT (orig_arg2) == DECL_CONTEXT (orig_arg3))
/* Two enumerators from the same enumeration can have different
   types when the enumeration is still being defined.  */;
+ else if (TYPE_ANONYMOUS_P (arg2_type)
+  || TYPE_ANONYMOUS_P (arg3_type))
+   /* Avoid warning for anonymous enums, probably just used as
+  named constants.  */;
   else if (complain  tf_warning)
 warning_at (loc, OPT_Wenum_compare, enumeral mismatch in 
conditional expression: %qT vs %qT,
Index: testsuite/g++.dg/warn/Wenum-compare-2.C
===
--- testsuite/g++.dg/warn/Wenum-compare-2.C (revision 0)
+++ testsuite/g++.dg/warn/Wenum-compare-2.C (working copy)
@@ -0,0 +1,10 @@
+// PR c++/60978
+// { dg-options -Wenum-compare }
+
+enum { A };
+enum { B };
+
+int foo(int x)
+{
+  return x ? A : B;
+}


Re: [C++ Patch] PR 60978

2014-12-02 Thread Jason Merrill
See my comment on the PR; I think the testcase illustrates why we still 
want this warning for anonymous enums.


Jason


Re: [C++ Patch] PR 60978

2014-12-02 Thread Paolo Carlini

Hi,

On 12/02/2014 11:01 PM, Jason Merrill wrote:
See my comment on the PR; I think the testcase illustrates why we 
still want this warning for anonymous enums.
Ok... Thus, barring further discussion, I will simply close the Bug as 
invalid.


Thanks!
Paolo.