This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Fix PR c++/27547: ICE on invalid operator=
- From: Volker Reichelt <reichelt at igpm dot rwth-aachen dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 11 May 2006 09:10:46 +0200 (CEST)
- Subject: [patch] Fix PR c++/27547: ICE on invalid operator=
Since GCC 3.4.0 the C++ frontend ICEs on the following code snippet:
int operator=(int);
void foo()
{
operator=(0);
}
bug.cc:1: error: 'int operator=(int)' must be a nonstatic member function
bug.cc: In function 'void foo()':
bug.cc:5: internal compiler error: in copy_fn_p, at cp/decl.c:8821
Please submit a full bug report, [etc.]
The compiler triggers the following assert at the beginning of copy_fn_p
where "d" is the "operator=":
gcc_assert (DECL_FUNCTION_MEMBER_P (d));
IMHO the assert is too strict here. As the testcase shows one can indeed
generate a non-member operator=. The compiler complains about it, but keeps
the declaration anyway.
The patch fixes the ICE by returning 0 if "d" is not a member function
This indicates that "d" is not a proper copy constructor or copy assignment
operator.
Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline, 4.1 branch, and 4.0 branch?
Regards,
Volker
:ADDPATCH C++:
2006-05-11 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/27547
* decl.c (copy_fn_p): Return early on non-member functions.
===================================================================
--- gcc/gcc/cp/decl.c (revision 113669)
+++ gcc/gcc/cp/decl.c (working copy)
@@ -8818,7 +8818,8 @@ copy_fn_p (tree d)
tree arg_type;
int result = 1;
- gcc_assert (DECL_FUNCTION_MEMBER_P (d));
+ if (!DECL_FUNCTION_MEMBER_P (d))
+ return 0;
if (TREE_CODE (d) == TEMPLATE_DECL
|| (DECL_TEMPLATE_INFO (d)
===================================================================
2006-05-11 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/27547
* g++.dg/other/operator1.C: New test.
===================================================================
--- gcc/gcc/testsuite/g++.dg/other/operator1.C 2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/other/operator1.C 2006-05-10 18:10:28 +0200
@@ -0,0 +1,9 @@
+// PR c++/27547
+// { dg-do compile }
+
+int operator=(int); // { dg-error "member function" }
+
+void foo()
+{
+ operator=(0);
+}
===================================================================