[C++ PATCH] fix pr 5719 (regression)
Nathan Sidwell
nathan@acm.org
Fri Apr 26 09:34:00 GMT 2002
Hi,
this fixes pr5719, a regression from 2.95 with -Weffc++.
the regresion is that we don't distinguish operator+ and operator+=.
It also looks to me that we've forgotten operator% - can someone with
Scott's book check what rule 23 is.
BTW, is there not a rule about the assignment operators returning
a reference?
I'm testing now, ok for mainline and 3.1?
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
The voices in my head told me to say this
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk
-------------- next part --------------
2002-04-26 Nathan Sidwell <nathan@codesourcery.com>
PR c++/5719
* decl.c (grok_op_properties): Assignment ops don't have to return
by value. operator% should.
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.866.2.25
diff -c -3 -p -r1.866.2.25 decl.c
*** cp/decl.c 23 Apr 2002 23:52:07 -0000 1.866.2.25
--- cp/decl.c 26 Apr 2002 16:26:53 -0000
*************** grok_op_properties (decl, friendp)
*** 12689,12698 ****
/* Effective C++ rule 23. */
if (warn_ecpp
&& arity == 2
&& (operator_code == PLUS_EXPR
|| operator_code == MINUS_EXPR
|| operator_code == TRUNC_DIV_EXPR
! || operator_code == MULT_EXPR)
&& TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == REFERENCE_TYPE)
warning ("`%D' should return by value", decl);
--- 12689,12700 ----
/* Effective C++ rule 23. */
if (warn_ecpp
&& arity == 2
+ && !DECL_ASSIGNMENT_OPERATOR_P (decl)
&& (operator_code == PLUS_EXPR
|| operator_code == MINUS_EXPR
|| operator_code == TRUNC_DIV_EXPR
! || operator_code == MULT_EXPR
! || operator_code == TRUNC_MOD_EXPR)
&& TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == REFERENCE_TYPE)
warning ("`%D' should return by value", decl);
-------------- next part --------------
// { dg-options -Weffc++ }
// { dg-do compile }
// Copyright (C) 2001 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 26 Apr 2002 <nathan@codesourcery.com>
// Bug 5719
class A
{
public:
A & operator+=( int );
A & operator+( int ); // { dg-warning "`A & A::operator+(int)' should return by value" "" }
A operator+=( float );
A operator+( float );
};
More information about the Gcc-patches
mailing list