Patchwork RFA (c-family): PATCH to remove C++-specific code from c-family check_case_value

login
register
mail settings
Submitter Jason Merrill
Date Oct. 27, 2010, 7:08 p.m.
Message ID <4CC878B4.6060101@redhat.com>
Download mbox | patch
Permalink /patch/69391/
State New
Headers show

Comments

Jason Merrill - Oct. 27, 2010, 7:08 p.m.
There's no reason for check_case_value to need to know about C++ 
constant expression rules; this patch moves the language-specific 
handling into the front end.

Tested x86_64-pc-linux-gnu.  OK for trunk?
Joseph S. Myers - Oct. 27, 2010, 8:22 p.m.
On Wed, 27 Oct 2010, Jason Merrill wrote:

> There's no reason for check_case_value to need to know about C++ constant
> expression rules; this patch moves the language-specific handling into the
> front end.
> 
> Tested x86_64-pc-linux-gnu.  OK for trunk?

C++-specific code in c-family is definitely covered by C++ maintainership 
(actually, I think all of c-family is).

Patch

commit 57bc5e0446e9a26a40168c6c1a651e48277e1ff9
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Oct 26 14:49:56 2010 -0400

    c-family/
    	* c-common.c (check_case_value): Remove special C++ code.
    cp/
    	* decl.c (finish_case_label): Use decl_constant_value.

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index a847be2..98568e8 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -2588,22 +2588,6 @@  check_case_value (tree value)
   if (value == NULL_TREE)
     return value;
 
-  /* ??? Can we ever get nops here for a valid case value?  We
-     shouldn't for C.  */
-  STRIP_TYPE_NOPS (value);
-  /* In C++, the following is allowed:
-
-       const int i = 3;
-       switch (...) { case i: ... }
-
-     So, we try to reduce the VALUE to a constant that way.  */
-  if (c_dialect_cxx ())
-    {
-      value = decl_constant_value (value);
-      STRIP_TYPE_NOPS (value);
-      value = fold (value);
-    }
-
   if (TREE_CODE (value) == INTEGER_CST)
     /* Promote char or short to int.  */
     value = perform_integral_promotions (value);
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 8b2af9cd..d73d109 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -2938,6 +2938,11 @@  finish_case_label (location_t loc, tree low_value, tree high_value)
   if (!check_switch_goto (switch_stack->level))
     return error_mark_node;
 
+  if (low_value)
+    low_value = decl_constant_value (low_value);
+  if (high_value)
+    high_value = decl_constant_value (high_value);
+
   r = c_add_case_label (loc, switch_stack->cases, cond,
 			SWITCH_STMT_TYPE (switch_stack->switch_stmt),
 			low_value, high_value);