summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog4
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/parser.c19
-rw-r--r--gcc/doc/extend.texi51
-rw-r--r--gcc/testsuite/ChangeLog9
-rw-r--r--gcc/testsuite/g++.dg/opt/max1.C2
-rw-r--r--gcc/testsuite/g++.dg/opt/pr7503-2.C2
-rw-r--r--gcc/testsuite/g++.dg/opt/pr7503-3.C2
-rw-r--r--gcc/testsuite/g++.dg/opt/pr7503-4.C2
-rw-r--r--gcc/testsuite/g++.dg/opt/pr7503-5.C2
-rw-r--r--gcc/testsuite/g++.dg/warn/minmax.C15
11 files changed, 64 insertions, 51 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9d0a7ef4499..2da080afb84 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,7 @@
+2005-03-22 Mark Mitchell <mark@codesourcery.com>
+
+ * doc/extend.texi: Deprecate C++ min/max operators.
+
2005-03-22 Zdenek Dvorak <dvorakz@suse.cz>
* tree-ssa-loop-ivopts.c (determine_iv_cost): Do not try to preserve
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 73dd59fde70..237fe33a018 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2005-03-22 Mark Mitchell <mark@codesourcery.com>
+
+ * parser.c (cp_parser_warn_min_max): New function.
+ (cp_parser_binary_expression): Use it.
+ (cp_parser_assignment_operator_opt): Likewise.
+ (cp_parser_operator): Likewise.
+
2005-03-22 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/19980
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index a6145406de9..d682f3a38aa 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -1787,6 +1787,16 @@ cp_parser_is_keyword (cp_token* token, enum rid keyword)
return token->keyword == keyword;
}
+/* A minimum or maximum operator has been seen. As these are
+ deprecated, issue a warning. */
+
+static inline void
+cp_parser_warn_min_max (void)
+{
+ if (warn_deprecated && !in_system_header)
+ warning ("minimum/maximum operators are deprecated");
+}
+
/* If not parsing tentatively, issue a diagnostic of the form
FILE:LINE: MESSAGE before TOKEN
where TOKEN is the next token in the input stream. MESSAGE
@@ -5401,6 +5411,9 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p)
{
/* 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);
/* Popping an entry off the stack means we completed a subexpression:
@@ -5656,10 +5669,12 @@ cp_parser_assignment_operator_opt (cp_parser* parser)
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:
@@ -8039,18 +8054,22 @@ cp_parser_operator (cp_parser* parser)
/* 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:
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 1258a60949c..f09338fbbfe 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -9130,7 +9130,6 @@ test specifically for GNU C++ (@pxref{Common Predefined Macros,,
Predefined Macros,cpp,The GNU C Preprocessor}).
@menu
-* Min and Max:: C++ Minimum and maximum operators.
* Volatiles:: What constitutes an access to a volatile object.
* Restricted Pointers:: C99 restricted pointers and references.
* Vague Linkage:: Where G++ puts inlines, vtables and such.
@@ -9147,51 +9146,6 @@ Predefined Macros,cpp,The GNU C Preprocessor}).
* Backwards Compatibility:: Compatibilities with earlier definitions of C++.
@end menu
-@node Min and Max
-@section Minimum and Maximum Operators in C++
-
-It is very convenient to have operators which return the ``minimum'' or the
-``maximum'' of two arguments. In GNU C++ (but not in GNU C),
-
-@table @code
-@item @var{a} <? @var{b}
-@findex <?
-@cindex minimum operator
-is the @dfn{minimum}, returning the smaller of the numeric values
-@var{a} and @var{b};
-
-@item @var{a} >? @var{b}
-@findex >?
-@cindex maximum operator
-is the @dfn{maximum}, returning the larger of the numeric values @var{a}
-and @var{b}.
-@end table
-
-These operations are not primitive in ordinary C++, since you can
-use a macro to return the minimum of two things in C++, as in the
-following example.
-
-@smallexample
-#define MIN(X,Y) ((X) < (Y) ? : (X) : (Y))
-@end smallexample
-
-@noindent
-You might then use @w{@samp{int min = MIN (i, j);}} to set @var{min} to
-the minimum value of variables @var{i} and @var{j}.
-
-However, side effects in @code{X} or @code{Y} may cause unintended
-behavior. For example, @code{MIN (i++, j++)} will fail, incrementing
-the smaller counter twice. The GNU C @code{typeof} extension allows you
-to write safe macros that avoid this kind of problem (@pxref{Typeof}).
-However, writing @code{MIN} and @code{MAX} as macros also forces you to
-use function-call notation for a fundamental arithmetic operation.
-Using GNU C++ extensions, you can write @w{@samp{int min = i <? j;}}
-instead.
-
-Since @code{<?} and @code{>?} are built into the compiler, they properly
-handle expressions with side-effects; @w{@samp{int min = i++ <? j++;}}
-works correctly.
-
@node Volatiles
@section When is a Volatile Object Accessed?
@cindex accessing volatiles
@@ -9838,6 +9792,11 @@ by one returning a different pointer type. This extension to the
covariant return type rules is now deprecated and will be removed from a
future version.
+The G++ minimum and maximum operators (@samp{<?} and @samp{>?}) and
+their compound forms (@samp{<?=}) and @samp{>?=}) have been deprecated
+and will be removed in a future version. Code using these operators
+should be modified to use @code{std::min} and @code{std::max} instead.
+
The named return value extension has been deprecated, and is now
removed from G++.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 95fa9495bfd..71347381142 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,12 @@
+2005-03-22 Mark Mitchell <mark@codesourcery.com>
+
+ * g++.dg/opt/max1.C: Run with -Wno-deprecated.
+ * g++.dg/opt/pr7503-2.C: Likewise.
+ * g++.dg/opt/pr7503-3.C: Likewise.
+ * g++.dg/opt/pr7503-4.C: Likewise.
+ * g++.dg/opt/pr7503-5.C: Likewise.
+ * g++.dg/warn/minmax.C: New test.
+
2005-03-22 Francois-Xavier Coudert <coudert@clipper.ens.fr>
* g77_intrinsics_funcs.f: New test.
diff --git a/gcc/testsuite/g++.dg/opt/max1.C b/gcc/testsuite/g++.dg/opt/max1.C
index 61b7021da66..10a6e57d92d 100644
--- a/gcc/testsuite/g++.dg/opt/max1.C
+++ b/gcc/testsuite/g++.dg/opt/max1.C
@@ -1,7 +1,7 @@
/* PR middle-end/19068 */
/* Test case by Andrew Pinski <pinskia@physics.uc.edu> */
/* { dg-do run } */
-/* { dg-options "-O2" } */
+/* { dg-options "-O2 -Wno-deprecated" } */
extern "C" void abort (void);
diff --git a/gcc/testsuite/g++.dg/opt/pr7503-2.C b/gcc/testsuite/g++.dg/opt/pr7503-2.C
index 68bb143e45e..02ce5988d70 100644
--- a/gcc/testsuite/g++.dg/opt/pr7503-2.C
+++ b/gcc/testsuite/g++.dg/opt/pr7503-2.C
@@ -1,6 +1,6 @@
// PR c++/7503
// { dg-do run }
-// { dg-options "-O2" }
+// { dg-options "-O2 -Wno-deprecated" }
extern "C" void abort();
diff --git a/gcc/testsuite/g++.dg/opt/pr7503-3.C b/gcc/testsuite/g++.dg/opt/pr7503-3.C
index 34d91ddb6c0..4e8de0f207c 100644
--- a/gcc/testsuite/g++.dg/opt/pr7503-3.C
+++ b/gcc/testsuite/g++.dg/opt/pr7503-3.C
@@ -1,6 +1,6 @@
// PR c++/7503
// { dg-do compile }
-// { dg-options "-O2" }
+// { dg-options "-O2 -Wno-deprecated" }
extern int A, B;
diff --git a/gcc/testsuite/g++.dg/opt/pr7503-4.C b/gcc/testsuite/g++.dg/opt/pr7503-4.C
index 06ac901229f..7ed70946984 100644
--- a/gcc/testsuite/g++.dg/opt/pr7503-4.C
+++ b/gcc/testsuite/g++.dg/opt/pr7503-4.C
@@ -1,6 +1,6 @@
// PR c++/7503
// { dg-do run }
-// { dg-options "-O2" }
+// { dg-options "-O2 -Wno-deprecated" }
extern "C" void abort();
diff --git a/gcc/testsuite/g++.dg/opt/pr7503-5.C b/gcc/testsuite/g++.dg/opt/pr7503-5.C
index 9e1e719f5c2..236ac93aa3a 100644
--- a/gcc/testsuite/g++.dg/opt/pr7503-5.C
+++ b/gcc/testsuite/g++.dg/opt/pr7503-5.C
@@ -1,6 +1,6 @@
// PR c++/7503
// { dg-do run }
-// { dg-options "-O2" }
+// { dg-options "-O2 -Wno-deprecated" }
extern "C" void abort();
diff --git a/gcc/testsuite/g++.dg/warn/minmax.C b/gcc/testsuite/g++.dg/warn/minmax.C
new file mode 100644
index 00000000000..7431bfc3c4e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/minmax.C
@@ -0,0 +1,15 @@
+int i, j, k;
+
+void f() {
+ i = j <? k; // { dg-warning "deprecated" }
+ i = j >? k; // { dg-warning "deprecated" }
+ i <?= j; // { dg-warning "deprecated" }
+ i >?= j; // { dg-warning "deprecated" }
+}
+
+struct S {
+ void operator<?(int); // { dg-warning "deprecated" }
+ void operator>?(int); // { dg-warning "deprecated" }
+ void operator<?=(int); // { dg-warning "deprecated" }
+ void operator>?=(int); // { dg-warning "deprecated" }
+};