This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch for "egcs/gcc/cp/decl.c"
- To: gcc-patches at gcc dot gnu dot org
- Subject: Patch for "egcs/gcc/cp/decl.c"
- From: Cosmin Truta <cosmint at cs dot ubbcluj dot ro>
- Date: Sun, 2 Apr 2000 12:03:35 +0300 (EEST)
Hi,
It happens that when compiling code like this
** begin buggy.cc
class C
{
public:
int operator + (undefined x); // The compiler dies here
};
!error_not_reached!; // and this error is not shown.
** end buggy.cc
The compiler dies with due to accessing a NULL pointer.
It happens in decl.c, at the end of the function grok_op_properties()
(spec. 13.4.0.8), when the simple "if (argtypes)" is not enough, as the
second iteration might yield a NULL value for argtypes, as shown in this
example.
I moved the check inside the for statement.
There is no performance penalty with this extra check.
The compiler simply displays the error message properly and goes further,
possibly showing the subsequent error messages, instead of stopping.
Best regards,
Cosmin
Index: egcs/gcc/cp/decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl.c,v
retrieving revision 1.579
diff -c -3 -p -r1.579 decl.c
*** decl.c 2000/03/27 01:26:17 1.579
--- decl.c 2000/04/02 08:45:08
*************** grok_op_properties (decl, virtualp, frie
*** 12296,12315 ****
cp_warning ("`%D' should return by value", decl);
/* 13.4.0.8 */
! if (argtypes)
! for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes))
! if (TREE_PURPOSE (argtypes))
! {
! TREE_PURPOSE (argtypes) = NULL_TREE;
! if (name == ansi_opname[(int) POSTINCREMENT_EXPR]
! || name == ansi_opname[(int) POSTDECREMENT_EXPR])
! {
! if (pedantic)
! cp_pedwarn ("`%D' cannot have default arguments", decl);
! }
! else
! cp_error ("`%D' cannot have default arguments", decl);
! }
}
}
--- 12296,12316 ----
cp_warning ("`%D' should return by value", decl);
/* 13.4.0.8 */
! for (; argtypes && argtypes != void_list_node;
! argtypes = TREE_CHAIN (argtypes))
! if (TREE_PURPOSE (argtypes))
! {
! TREE_PURPOSE (argtypes) = NULL_TREE;
! if (name == ansi_opname[(int) POSTINCREMENT_EXPR]
! || name == ansi_opname[(int) POSTDECREMENT_EXPR])
! {
! if (pedantic)
! cp_pedwarn ("`%D' cannot have default arguments", decl);
! }
! else
! cp_error ("`%D' cannot have default arguments", decl);
! }
!
}
}
Sun Apr 2 2000 Cosmin Truta <cosmint@cs.ubbcluj.ro>
* decl.c (grok_op_properties): Add an extra check of argtypes.