diff mbox

[C++] PR 60978

Message ID 547DFD42.2070906@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Dec. 2, 2014, 5:56 p.m. UTC
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.carlini@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.carlini@oracle.com>

	PR c++/60978
	* g++.dg/warn/Wenum-compare-2.C: New.

Comments

Jason Merrill Dec. 2, 2014, 10:01 p.m. UTC | #1
See my comment on the PR; I think the testcase illustrates why we still 
want this warning for anonymous enums.

Jason
Paolo Carlini Dec. 2, 2014, 10:31 p.m. UTC | #2
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.
diff mbox

Patch

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