This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]