extend.texi: Deprecate C++ min/max operators.
* doc/extend.texi: Deprecate C++ min/max operators. * 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. * 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. From-SVN: r96899
This commit is contained in:
committed by
Mark Mitchell
parent
0dc8f32738
commit
8ff24a798e
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
+5
-46
@@ -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++.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// PR c++/7503
|
||||
// { dg-do run }
|
||||
// { dg-options "-O2" }
|
||||
// { dg-options "-O2 -Wno-deprecated" }
|
||||
|
||||
extern "C" void abort();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// PR c++/7503
|
||||
// { dg-do compile }
|
||||
// { dg-options "-O2" }
|
||||
// { dg-options "-O2 -Wno-deprecated" }
|
||||
|
||||
extern int A, B;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// PR c++/7503
|
||||
// { dg-do run }
|
||||
// { dg-options "-O2" }
|
||||
// { dg-options "-O2 -Wno-deprecated" }
|
||||
|
||||
extern "C" void abort();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// PR c++/7503
|
||||
// { dg-do run }
|
||||
// { dg-options "-O2" }
|
||||
// { dg-options "-O2 -Wno-deprecated" }
|
||||
|
||||
extern "C" void abort();
|
||||
|
||||
|
||||
@@ -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" }
|
||||
};
|
||||
Reference in New Issue
Block a user