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]

Patch for PR 28288 & PR 14556, Remove <? and >? operators from C++


This patch resolves PR c++/28288 and PR c++/14556 by removing the <?,
>?, <?=, and >?= operators from C++.  The comments in the PR say that
they were supposed to be removed in 4.1 but they were not.  Both the 4.0
and 4.1 branches do give a 'depreciated' message when they are used.

This patch is to remove them from 4.2 and, as a side effect, get rid of
the ICE failures reported in the bug reports and thus resolve the two
defects.  I do not intend to backport this to the 4.1 branch.

Most of the changes are in the libcpp directory, but I also changed two
files in gcc/cp and removed a number of tests.  I added one test to make
sure we give errors on these operators now instead of just warnings.

OK for Checkin?  Tested on IA64 HP-UX and Linux with no regressions.

Steve Ellcey
sje@cup.hp.com

--------------- libcpp changes -----------------------

2006-08-09  Steve Ellcey  <sje@cup.hp.com>

	PR c++/28288
	PR c++/14556
	* include/cpplib.h: Remove <?, >?, <?=, and >?= tokens.
	(CPP_LAST_EQ): Change.
	(CPP_LAST_PUNCTUATOR): Change.
	* expr.c (cpp_operator): Remove MIN and MAX.
	(reduce): Remove CPP_MIN and CPP_MAX.
	(num_binary_op): Ditto.
	* lex.c (_cpp_lex_direct): Ditto.
	(cpp_avoid_paste): Remove ? as legal symbol after > or <.

Index: include/cpplib.h
===================================================================
--- include/cpplib.h	(revision 116028)
+++ include/cpplib.h	(working copy)
@@ -51,7 +51,10 @@ struct _cpp_file;
 
    The first group, to CPP_LAST_EQ, can be immediately followed by an
    '='.  The lexer needs operators ending in '=', like ">>=", to be in
-   the same order as their counterparts without the '=', like ">>".  */
+   the same order as their counterparts without the '=', like ">>".
+
+   See the cpp_operator table optab in expr.c if you change the order or
+   add or remove anything in the first group.  */
 
 #define TTYPE_TABLE							\
   OP(EQ,		"=")						\
@@ -68,8 +71,6 @@ struct _cpp_file;
   OP(XOR,		"^")						\
   OP(RSHIFT,		">>")						\
   OP(LSHIFT,		"<<")						\
-  OP(MIN,		"<?")	/* extension */				\
-  OP(MAX,		">?")						\
 									\
   OP(COMPL,		"~")						\
   OP(AND_AND,		"&&")	/* logical */				\
@@ -97,8 +98,6 @@ struct _cpp_file;
   OP(XOR_EQ,		"^=")						\
   OP(RSHIFT_EQ,		">>=")						\
   OP(LSHIFT_EQ,		"<<=")						\
-  OP(MIN_EQ,		"<?=")	/* extension */				\
-  OP(MAX_EQ,		">?=")						\
   /* Digraphs together, beginning with CPP_FIRST_DIGRAPH.  */		\
   OP(HASH,		"#")	/* digraphs */				\
   OP(PASTE,		"##")						\
@@ -146,9 +145,9 @@ enum cpp_ttype
   N_TTYPES,
 
   /* Positions in the table.  */
-  CPP_LAST_EQ        = CPP_MAX,
+  CPP_LAST_EQ        = CPP_LSHIFT,
   CPP_FIRST_DIGRAPH  = CPP_HASH,
-  CPP_LAST_PUNCTUATOR= CPP_DOT_STAR,
+  CPP_LAST_PUNCTUATOR= CPP_ATSIGN,
   CPP_LAST_CPP_OP    = CPP_LESS_EQ
 };
 #undef OP


Index: expr.c
===================================================================
--- expr.c	(revision 116028)
+++ expr.c	(working copy)
@@ -668,9 +668,6 @@ static const struct cpp_operator
   /* RSHIFT */		{13, LEFT_ASSOC},
   /* LSHIFT */		{13, LEFT_ASSOC},
 
-  /* MIN */		{10, LEFT_ASSOC | CHECK_PROMOTION},
-  /* MAX */		{10, LEFT_ASSOC | CHECK_PROMOTION},
-
   /* COMPL */		{16, NO_L_OPERAND},
   /* AND_AND */		{6, LEFT_ASSOC},
   /* OR_OR */		{5, LEFT_ASSOC},
@@ -882,8 +879,6 @@ reduce (cpp_reader *pfile, struct op *to
 	case CPP_MINUS:
 	case CPP_RSHIFT:
 	case CPP_LSHIFT:
-	case CPP_MIN:
-	case CPP_MAX:
 	case CPP_COMMA:
 	  top[-1].value = num_binary_op (pfile, top[-1].value,
 					 top->value, top->op);
@@ -1309,7 +1304,6 @@ num_binary_op (cpp_reader *pfile, cpp_nu
 {
   cpp_num result;
   size_t precision = CPP_OPTION (pfile, precision);
-  bool gte;
   size_t n;
 
   switch (op)
@@ -1334,21 +1328,6 @@ num_binary_op (cpp_reader *pfile, cpp_nu
 	lhs = num_lshift (lhs, precision, n);
       else
 	lhs = num_rshift (lhs, precision, n);
-      break;
-
-      /* Min / Max.  */
-    case CPP_MIN:
-    case CPP_MAX:
-      {
-	bool unsignedp = lhs.unsignedp || rhs.unsignedp;
-
-	gte = num_greater_eq (lhs, rhs, precision);
-	if (op == CPP_MIN)
-	  gte = !gte;
-	if (!gte)
-	  lhs = rhs;
-	lhs.unsignedp = unsignedp;
-      }
       break;
 
       /* Arithmetic.  */


Index: lex.c
===================================================================
--- lex.c	(revision 116028)
+++ lex.c	(working copy)
@@ -1052,11 +1052,6 @@ _cpp_lex_direct (cpp_reader *pfile)
 	  buffer->cur++;
 	  IF_NEXT_IS ('=', CPP_LSHIFT_EQ, CPP_LSHIFT);
 	}
-      else if (*buffer->cur == '?' && CPP_OPTION (pfile, cplusplus))
-	{
-	  buffer->cur++;
-	  IF_NEXT_IS ('=', CPP_MIN_EQ, CPP_MIN);
-	}
       else if (CPP_OPTION (pfile, digraphs))
 	{
 	  if (*buffer->cur == ':')
@@ -1083,11 +1078,6 @@ _cpp_lex_direct (cpp_reader *pfile)
 	  buffer->cur++;
 	  IF_NEXT_IS ('=', CPP_RSHIFT_EQ, CPP_RSHIFT);
 	}
-      else if (*buffer->cur == '?' && CPP_OPTION (pfile, cplusplus))
-	{
-	  buffer->cur++;
-	  IF_NEXT_IS ('=', CPP_MAX_EQ, CPP_MAX);
-	}
       break;
 
     case '%':
@@ -1472,8 +1462,8 @@ cpp_avoid_paste (cpp_reader *pfile, cons
 
   switch (a)
     {
-    case CPP_GREATER:	return c == '>' || c == '?';
-    case CPP_LESS:	return c == '<' || c == '?' || c == '%' || c == ':';
+    case CPP_GREATER:	return c == '>';
+    case CPP_LESS:	return c == '<' || c == '%' || c == ':';
     case CPP_PLUS:	return c == '+';
     case CPP_MINUS:	return c == '-' || c == '>';
     case CPP_DIV:	return c == '/' || c == '*'; /* Comments.  */


--------------- gcc/cp changes -----------------------

2006-08-09  Steve Ellcey  <sje@cup.hp.com>

	PR c++/28288
	PR c++/14556
	* operators.def: Remove <?, ?>, <?=, and >?= operators.
	* parser.c: Remove CPP_MIN, CPP_MAX, CPP_MIN_EQ, and CPP_MAX_EQ.


Index: operators.def
===================================================================
--- operators.def	(revision 116028)
+++ operators.def	(working copy)
@@ -129,9 +129,6 @@ DEF_SIMPLE_OPERATOR ("->", COMPONENT_REF
 DEF_SIMPLE_OPERATOR ("[]", ARRAY_REF, "ix", 2)
 DEF_SIMPLE_OPERATOR ("++", POSTINCREMENT_EXPR, "pp", 2)
 DEF_SIMPLE_OPERATOR ("--", POSTDECREMENT_EXPR, "mm", 2)
-/* These operators are GNU extensions.  */
-DEF_SIMPLE_OPERATOR ("<?", MIN_EXPR, "v23min", 2)
-DEF_SIMPLE_OPERATOR (">?", MAX_EXPR, "v23max", 2)
 /* This one is needed for mangling.  */
 DEF_SIMPLE_OPERATOR ("::", SCOPE_REF, "sr", 2)
 
@@ -147,9 +144,6 @@ DEF_ASSN_OPERATOR ("|=", BIT_IOR_EXPR, "
 DEF_ASSN_OPERATOR ("^=", BIT_XOR_EXPR, "eO", 2)
 DEF_ASSN_OPERATOR ("<<=", LSHIFT_EXPR, "lS", 2)
 DEF_ASSN_OPERATOR (">>=", RSHIFT_EXPR, "rS", 2)
-/* These operators are GNU extensions.  */
-DEF_ASSN_OPERATOR ("<?=", MIN_EXPR, "v23miN", 2)
-DEF_ASSN_OPERATOR (">?=", MAX_EXPR, "v23maX", 2)
 
 /* Ternary operators.  */
 DEF_SIMPLE_OPERATOR ("?:", COND_EXPR, "qu", 3)


Index: parser.c
===================================================================
--- parser.c	(revision 116028)
+++ parser.c	(working copy)
@@ -1150,8 +1150,6 @@ static const cp_parser_binary_operations
   { CPP_GREATER, GT_EXPR, PREC_RELATIONAL_EXPRESSION },
   { CPP_LESS_EQ, LE_EXPR, PREC_RELATIONAL_EXPRESSION },
   { CPP_GREATER_EQ, GE_EXPR, PREC_RELATIONAL_EXPRESSION },
-  { CPP_MIN, MIN_EXPR, PREC_RELATIONAL_EXPRESSION },
-  { CPP_MAX, MAX_EXPR, PREC_RELATIONAL_EXPRESSION },
 
   { CPP_EQ_EQ, EQ_EXPR, PREC_EQUALITY_EXPRESSION },
   { CPP_NOT_EQ, NE_EXPR, PREC_EQUALITY_EXPRESSION },
@@ -5613,8 +5611,6 @@ cp_parser_binary_expression (cp_parser* 
     {
       /* Get an operator token.  */
       token = cp_lexer_peek_token (parser->lexer);
-      if (token->type == CPP_MIN || token->type == CPP_MAX)
-	cp_parser_warn_min_max ();
 
       new_prec = TOKEN_PRECEDENCE (token);
 
@@ -5869,16 +5865,6 @@ cp_parser_assignment_operator_opt (cp_pa
       op = BIT_IOR_EXPR;
       break;
 
-    case CPP_MIN_EQ:
-      op = MIN_EXPR;
-      cp_parser_warn_min_max ();
-      break;
-
-    case CPP_MAX_EQ:
-      op = MAX_EXPR;
-      cp_parser_warn_min_max ();
-      break;
-
     default:
       /* Nothing else is an assignment operator.  */
       op = ERROR_MARK;
@@ -8329,27 +8315,6 @@ cp_parser_operator (cp_parser* parser)
       /* Look for the matching `]'.  */
       cp_parser_require (parser, CPP_CLOSE_SQUARE, "`]'");
       return ansi_opname (ARRAY_REF);
-
-      /* Extensions.  */
-    case CPP_MIN:
-      id = ansi_opname (MIN_EXPR);
-      cp_parser_warn_min_max ();
-      break;
-
-    case CPP_MAX:
-      id = ansi_opname (MAX_EXPR);
-      cp_parser_warn_min_max ();
-      break;
-
-    case CPP_MIN_EQ:
-      id = ansi_assopname (MIN_EXPR);
-      cp_parser_warn_min_max ();
-      break;
-
-    case CPP_MAX_EQ:
-      id = ansi_assopname (MAX_EXPR);
-      cp_parser_warn_min_max ();
-      break;
 
     default:
       /* Anything else is an error.  */


--------------- gcc/testsuite changes -----------------------

2006-08-09  Steve Ellcey  <sje@cup.hp.com>

	PR c++/28288
	PR c++/14556
	* g++.old-deja/g++.warn/compare1.C: Delete.
	* g++.dg/opt/pr7503-2.C: Delete.
	* g++.dg/opt/pr7503-3.C: Delete.
	* g++.dg/opt/pr7503-4.C: Delete.
	* g++.dg/opt/pr7503-5.C: Delete.
	* g++.dg/opt/max1.C: Delete.
	* g++.dg/warn/minmax.C: Delete.
	* g++.dg/expr/minmax.C: New test.

Index: g++.dg/expr/minmax.C
===================================================================
--- g++.dg/expr/minmax.C	(revision 0)
+++ g++.dg/expr/minmax.C	(revision 0)
@@ -0,0 +1,14 @@
+// { dg-do compile }
+
+void f(void)
+{
+	int a, b;
+	(a >? b) = 1; // { dg-error "" }
+}
+
+
+void g(void)
+{
+	int a, b;
+	(a <? b) = 1; // { dg-error "" }
+}


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