This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH for 4.0/4.1] Fix PR20381 regression (ICE taking addressof member)
- From: Kriang Lerdsuwanakij <lerdsuwa at users dot sf dot net>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 10 Mar 2005 22:18:24 +0700
- Subject: [C++ PATCH for 4.0/4.1] Fix PR20381 regression (ICE taking addressof member)
- Reply-to: lerdsuwa at users dot sf dot net
Hi
This patch fixes the ICE PR20381 in mainline and 4.0. The ICE in
function 'build_unary_op' is due to passing ADDR_EXPR containing
OFFSET_REF to 'build_ptrmemfunc'. Calling build_ptrmemfunc to
create PTRMEM_CST in build_ptrmemfunc is not necessary here since
we just want to compute the type for NON_DEPENDENT_EXPR. The code
here is only executed for template case.
The change does not affect code in non-template. For non-template
case, it is resolved to PTRMEM_CST by a call to 'unary_complex_lvalue'
appeared several lines up in 'build_unary_op'. (The logic in
this area of frontend is nasty and can be simplified.)
Tested on i686-pc-linux-gnu. OK for mainline and 4.0?
--Kriang
2005-03-10 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/20381
* typeck.c (build_unary_op) <case ADDR_EXPR>: Don't call
build_ptrmemfunc for OFFSET_REF.
2005-03-10 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/20381
* g++.dg/template/ptrmem12.C: New test.
diff -cprN gcc-main-save/gcc/cp/typeck.c gcc-main-new/gcc/cp/typeck.c
*** gcc-main-save/gcc/cp/typeck.c Tue Mar 8 22:59:12 2005
--- gcc-main-new/gcc/cp/typeck.c Thu Mar 10 17:46:15 2005
*************** build_unary_op (enum tree_code code, tre
*** 4057,4063 ****
{
addr = build_address (arg);
if (TREE_CODE (arg) == OFFSET_REF)
! PTRMEM_OK_P (addr) = PTRMEM_OK_P (arg);
}
else if (TREE_CODE (TREE_OPERAND (arg, 1)) == BASELINK)
{
--- 4057,4066 ----
{
addr = build_address (arg);
if (TREE_CODE (arg) == OFFSET_REF)
! {
! PTRMEM_OK_P (addr) = PTRMEM_OK_P (arg);
! return addr;
! }
}
else if (TREE_CODE (TREE_OPERAND (arg, 1)) == BASELINK)
{
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/ptrmem12.C gcc-main-new/gcc/testsuite/g++.dg/template/ptrmem12.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/ptrmem12.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/ptrmem12.C Wed Mar 9 19:35:16 2005
***************
*** 0 ****
--- 1,17 ----
+ // { dg-do compile }
+
+ // Origin: Michael Cieslinski <micis@gmx.de>
+ // Martin Reinecke <martin@mpa-garching.mpg.de>
+
+ // PR c++/20381: ICE taking address of member function in template.
+
+ class foo {
+ public:
+ int f1(int);
+ };
+
+ template<typename T> class bar: public foo {
+ void baz () {
+ &foo::f1;
+ }
+ };