Bug 21853 - [3.4/4.0/4.1 Regression] constness of pointer to data member ignored
Summary: [3.4/4.0/4.1 Regression] constness of pointer to data member ignored
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 3.4.5
Assignee: Mark Mitchell
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2005-06-01 00:05 UTC by David Krauss
Modified: 2005-06-03 23:25 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 2.95.3
Known to fail: 3.3.3 3.4.0 4.0.0 4.1.0 3.0.4 3.2.3
Last reconfirmed: 2005-06-01 00:11:22


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Krauss 2005-06-01 00:05:17 UTC
When casting a pointer to const to a pointer to const pointer to data member
type, the constness of the ptdm is ignored. This breaks ptdm members of
boost::variant union types. Example code:

struct blah {
	int a;
};

int main( int argc, char ** argv ) {
	int blah::* ptdma = &blah::a;

	const void *ptdmv = static_cast< void * >( &ptdma );

	int blah::* const ptdmb = * static_cast< int blah::* const * >( ptdmv );

	return 0;
}

This code compiles fine on the Comeau web test-drive. GCC 3.1, 3.4.3, and 4.0.0
all choke on the second static_cast. (I'm only filing for 4.0.0.)

More stats:

% /usr/intel/pkgs/gcc/4.0.0/bin/g++ -v -save-temps test2.cpp
Reading specs from
/nfs/site/itools/i386_linux24/pkgs/gcc/4.0.0/bin/../lib/gcc/i686-pc-linux-gnu/4.0.0/specs
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.0.0/configure --prefix=/usr/intel/pkgs/gcc/4.0.0
--with-as=/usr/intel/pkgs/gcc/4.0.0/bin/gas
--with-ld=/usr/intel/pkgs/gcc/4.0.0/bin/gld --disable-libgcj
--enable-languages=c,c++,objc
Thread model: posix
gcc version 4.0.0
 /nfs/site/itools/i386_linux24/pkgs/gcc/4.0.0/bin/../libexec/gcc/i686-pc-linux-gnu/4.0.0/cc1plus
-E -quiet -v -iprefix
/nfs/site/itools/i386_linux24/pkgs/gcc/4.0.0/bin/../lib/gcc/i686-pc-linux-gnu/4.0.0/
-D_GNU_SOURCE test2.cpp -mtune=pentiumpro -fpch-preprocess -o test2.ii
ignoring nonexistent directory
"/nfs/site/itools/i386_linux24/pkgs/gcc/4.0.0/bin/../lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../i686-pc-linux-gnu/include"
ignoring duplicate directory
"/usr/intel/pkgs/gcc/4.0.0/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0"
ignoring duplicate directory
"/usr/intel/pkgs/gcc/4.0.0/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/i686-pc-linux-gnu"
ignoring duplicate directory
"/usr/intel/pkgs/gcc/4.0.0/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/backward"
ignoring duplicate directory
"/usr/intel/pkgs/gcc/4.0.0/lib/gcc/i686-pc-linux-gnu/4.0.0/include"
ignoring nonexistent directory
"/usr/intel/pkgs/gcc/4.0.0/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /nfs/site/itools/i386_linux24/pkgs/gcc/4.0.0/bin/../lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0
 /nfs/site/itools/i386_linux24/pkgs/gcc/4.0.0/bin/../lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/i686-pc-linux-gnu
 /nfs/site/itools/i386_linux24/pkgs/gcc/4.0.0/bin/../lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../include/c++/4.0.0/backward
 /nfs/site/itools/i386_linux24/pkgs/gcc/4.0.0/bin/../lib/gcc/i686-pc-linux-gnu/4.0.0/include
 /usr/local/include
 /usr/intel/pkgs/gcc/4.0.0/include
 /usr/include
End of search list.
 /nfs/site/itools/i386_linux24/pkgs/gcc/4.0.0/bin/../libexec/gcc/i686-pc-linux-gnu/4.0.0/cc1plus
-fpreprocessed test2.ii -quiet -dumpbase test2.cpp -mtune=pentiumpro -auxbase
test2 -version -o test2.s
GNU C++ version 4.0.0 (i686-pc-linux-gnu)
        compiled by GNU C version 3.4.2.
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128505
test2.cpp: In function 'int main(int, char**)':
test2.cpp:10: error: static_cast from type 'const void*' to type 'const int
blah::* const* const' casts away constness
Comment 1 Andrew Pinski 2005-06-01 00:11:04 UTC
Confirmed, a regression from 2.95.3 where we accepted the code.
Comment 2 Andrew Pinski 2005-06-01 00:12:11 UTC
This has been failing since at least 2000-12-31.
Comment 3 David Krauss 2005-06-01 01:44:38 UTC
Subject: RE:  [3.4/4.0/4.1 Regression] constness of pointer to data member ignored

Yo Andrew!!!!

How's it hangin'?

Sorry to say, my address means what it looks like...

	- David


-----Original Message-----
From: pinskia at gcc dot gnu dot org [mailto:gcc-bugzilla@gcc.gnu.org] 
Sent: Tuesday, May 31, 2005 5:12 PM
To: Krauss, David M
Subject: [Bug c++/21853] [3.4/4.0/4.1 Regression] constness of pointer
to data member ignored


------- Additional Comments From pinskia at gcc dot gnu dot org
2005-06-01 00:12 -------
This has been failing since at least 2000-12-31.

Comment 4 CVS Commits 2005-06-03 23:22:23 UTC
Subject: Bug 21853

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2005-06-03 23:22:11

Modified files:
	gcc/cp         : ChangeLog typeck.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/expr: static_cast6.C 

Log message:
	PR c++/21853
	* typeck.c (casts_away_constness_r): Do not drop cv-qualifiers on
	the pointed-to type for a pointer-to-member.
	
	PR c++/21853
	* g++.dg/expr/static_cast6.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4773&r2=1.4774
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.632&r2=1.633
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5587&r2=1.5588
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/static_cast6.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 5 CVS Commits 2005-06-03 23:24:03 UTC
Subject: Bug 21853

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	mmitchel@gcc.gnu.org	2005-06-03 23:23:41

Modified files:
	gcc/cp         : ChangeLog typeck.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/expr: static_cast6.C 

Log message:
	PR c++/21853
	* typeck.c (casts_away_constness_r): Do not drop cv-qualifiers on
	the pointed-to type for a pointer-to-member.
	
	PR c++/21853
	* g++.dg/expr/static_cast6.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.4648.2.56&r2=1.4648.2.57
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.8&r2=1.616.2.9
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.222&r2=1.5084.2.223
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/static_cast6.C.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1

Comment 6 CVS Commits 2005-06-03 23:25:01 UTC
Subject: Bug 21853

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	mmitchel@gcc.gnu.org	2005-06-03 23:24:54

Modified files:
	gcc/cp         : ChangeLog typeck.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/expr: static_cast6.C 

Log message:
	PR c++/21853
	* typeck.c (casts_away_constness_r): Do not drop cv-qualifiers on
	the pointed-to type for a pointer-to-member.
	
	PR c++/21853
	* g++.dg/expr/static_cast6.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.221&r2=1.3892.2.222
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.519.2.27&r2=1.519.2.28
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.400&r2=1.3389.2.401
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/static_cast6.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.4.1

Comment 7 Mark Mitchell 2005-06-03 23:25:53 UTC
Fixed in 3.4.5.