Bug 20734 - [4.0/4.1 Regression] rejects valid pointer to member
Summary: [4.0/4.1 Regression] rejects valid pointer to member
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P1 critical
Target Milestone: 4.0.0
Assignee: Mark Mitchell
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2005-04-03 00:03 UTC by Stefan Straßer
Modified: 2005-04-06 06:28 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-04-03 06:42:03


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Straßer 2005-04-03 00:03:43 UTC
error: cannot convert 'int*' to 'int A::*' for argument '1' to 'void blah(int A::*)'


struct A;
void blah(int A::*);
struct A{
  int a;
};
template<typename T> //remove this line to make it work
void hoho(){
  blah(&A::a);
}


compiles on gcc up to early 4.0, icc and comeau
Comment 1 Gabriel Dos Reis 2005-04-03 02:36:08 UTC
Subject: Re:  New: rejects valid pointer to member

"sstrasser at systemhaus-gruppe dot de" <gcc-bugzilla@gcc.gnu.org> writes:

| error: cannot convert 'int*' to 'int A::*' for argument '1' to 'void blah(int A::*)'

This is clearly a bug in GCC.

-- Gaby
Comment 2 Andrew Pinski 2005-04-03 06:28:25 UTC
Confirmed.
Comment 3 Andrew Pinski 2005-04-03 06:42:03 UTC
This worked with 20050225, right before 4.0.0 was branched.
But it failed with 20050325.
Comment 4 Andrew Pinski 2005-04-03 17:18:20 UTC
This is related to PR 20465 and PR 20381 which you fixed with:
2005-03-22  Nathan Sidwell  <nathan@codesourcery.com>

        PR c++/20465
        PR c++/20381
        * typeck.c (build_ptrmemfunc): Allow OFFSET_REF when processing a
        template.

Could you look into this?
Comment 5 Andrew Pinski 2005-04-03 17:50:07 UTC
It also fails with "4.1.0 20050308".
I think this was caused by:
2005-03-05  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

        PR c++/19311
        * init.c (build_offset_ref): Don't build non-dependent SCOPE_REF.
        * pt.c (build_non_dependent_expr): Don't build NON_DEPENDENT_EXPR
        for OFFSET_TYPE.
        * typeck.c (build_x_unary_op): Don't build non-dependent SCOPE_REF.
        Also set PTRMEM_OK_P for NON_DEPENDENT_EXPR.
        (build_unary_op): Handle building ADDR_EXPR of OFFSET_REF inside
        template.
Comment 6 GCC Commits 2005-04-06 05:35:57 UTC
Subject: Bug 20734

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	mmitchel@gcc.gnu.org	2005-04-06 05:35:50

Modified files:
	gcc/cp         : cp-tree.def init.c typeck.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/template: ptrmem13.C 

Log message:
	PR c++/20734
	* cp-tree.def (OFFSET_REF): Correct comments.
	* init.c (build_offset_ref): Remove misleading comment.
	* typeck.c (build_unary_op): Handle pointer-to-member creation
	here, rather than ...
	(unary_complex_lvalue): ... here.
	
	PR c++/20734
	* g++.dg/template/ptrmem13.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.def.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.94&r2=1.94.4.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.412.2.3&r2=1.412.2.4
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.616.2.4&r2=1.616.2.5
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.106&r2=1.5084.2.107
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/ptrmem13.C.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1

Comment 7 GCC Commits 2005-04-06 05:38:44 UTC
Subject: Bug 20734

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2005-04-06 05:38:34

Modified files:
	gcc/cp         : cp-tree.def init.c typeck.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/template: ptrmem13.C 

Log message:
	PR c++/20734
	* cp-tree.def (OFFSET_REF): Correct comments.
	* init.c (build_offset_ref): Remove misleading comment.
	* typeck.c (build_unary_op): Handle pointer-to-member creation
	here, rather than ...
	(unary_complex_lvalue): ... here.
	
	PR c++/20734
	* g++.dg/template/ptrmem13.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.def.diff?cvsroot=gcc&r1=1.94&r2=1.95
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&r1=1.416&r2=1.417
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.622&r2=1.623
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5292&r2=1.5293
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/ptrmem13.C.diff?cvsroot=gcc&r1=1.1&r2=1.2

Comment 8 Mark Mitchell 2005-04-06 05:40:32 UTC
Fixed in 4.0.
Comment 9 Stefan Straßer 2005-04-06 06:28:51 UTC
the file which has led to the test case above compiles ok, too