Bug 14803

Summary: [3.4/4.0 regression] Spurious warnings on conversion of pointers to member functions
Product: gcc Reporter: Joe Buck <jbuck>
Component: c++Assignee: Mark Mitchell <mark>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs, mmitchel
Priority: P2 Keywords: diagnostic
Version: 3.4.0   
Target Milestone: 3.4.0   
Host: Target:
Build: Known to work: 2.95.3 3.2.3 3.3.3
Known to fail: 3.4.0 4.0.0 tree-ssa Last reconfirmed: 2004-03-31 23:51:07
Attachments: test case

Description Joe Buck 2004-03-31 23:44:45 UTC
The example comes from the widely used SystemC library.  3.4 and later versions
of the compiler produce the spurious warning for some, but not all, explicit
conversions from a pointer to member function of a derived class type, to a
pointer to member function of a base class type.  The standard explcitly states
that such conversions are valid.  The diagnostic is

warning: overflow in implicit constant conversion

This construct appears a lot in SystemC, as it represents actions to be
scheduled as pointers to member functions.
Comment 1 Joe Buck 2004-03-31 23:45:37 UTC
Created attachment 6021 [details]
test case
Comment 2 Wolfgang Bangerth 2004-03-31 23:54:08 UTC
Confirmed. The warning message is a) not justified, and b) profoundly  
unhelpful!  
  
W.  
Comment 3 Andrew Pinski 2004-04-01 02:04:40 UTC
For some reason the expression has an overflow:
<integer_cst 0x401360a0 type <integer_type 0x400505e8 int> constant static overflow -4>
At typeck.c:5497 (in build_ptrmemfunc, at the assert)
n is <nop_expr 0x417dc5c0
    type <integer_type 0x417108b8 int SI
        size <integer_cst 0x4170e360 constant invariant 32>
        unit size <integer_cst 0x4170e400 constant invariant 4>
        align 32 symtab 0 alias set -1 precision 32 min <integer_cst 0x4170e3c0 -2147483648> max 
<integer_cst 0x4170e3e0 2147483647>
        pointer_to_this <pointer_type 0x4171d7c0>>
    constant invariant
    arg 0 <integer_cst 0x41790780 type <integer_type 0x4171d174> constant invariant -4>>
and delta is:
<nop_expr 0x417dc5e0
    type <integer_type 0x417108b8 int SI
        size <integer_cst 0x4170e360 constant invariant 32>
        unit size <integer_cst 0x4170e400 constant invariant 4>
        align 32 symtab 0 alias set -1 precision 32 min <integer_cst 0x4170e3c0 -2147483648> max 
<integer_cst 0x4170e3e0 2147483647>
        pointer_to_this <pointer_type 0x4171d7c0>>
    constant invariant
    arg 0 <integer_cst 0x4170ea80 type <integer_type 0x4171d000 long unsigned int> constant 
invariant 0>>
So when they are added together it sets the overflow bit for some reason (maybe setting the overflow 
bit to 0 will work).
Comment 4 Mark Mitchell 2004-04-01 02:46:53 UTC
Working on a fix.
Comment 5 GCC Commits 2004-04-01 23:15:07 UTC
Subject: Bug 14803

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-04-01 23:14:56

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

Log message:
	PR c++/14803
	* typeck.c (get_delta_difference): Call fold before returning the
	value.
	
	PR c++/14803
	* g++.dg/inherit/ptrmem1.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4024&r2=1.4025
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.538&r2=1.539
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3649&r2=1.3650
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/inherit/ptrmem1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 6 Mark Mitchell 2004-04-01 23:18:27 UTC
Fixed in GCC 3.4.