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