Bug 10468 - [3.3 Regression] const typeof(x) is non-const, but only in templates
Summary: [3.3 Regression] const typeof(x) is non-const, but only in templates
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P3 normal
Target Milestone: 3.3.1
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2003-04-23 20:36 UTC by mgoodman
Modified: 2003-06-27 22:47 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
test.ii (152 bytes, text/x-c++)
2003-05-21 15:17 UTC, mgoodman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mgoodman 2003-04-23 20:36:00 UTC
gcc interprets the type of t1 as int& instead of const int& in the attached code.

The error shows up in the gcc-3_2-branch as well but the message is different.

The code compiles in gcc 2.95.3.

Release:
gcc version 3.4 20030423 (experimental)

Environment:
Red Hat Linux 9

How-To-Repeat:
gcc -c -o test test.ii
Comment 1 Wolfgang Bangerth 2003-04-23 21:47:56 UTC
State-Changed-From-To: open->feedback
State-Changed-Why: Why should it be different than what gcc does? Can you
    point to a certain paragraph in the standard? I'd think
    gcc is right.
    
    Wolfgang
Comment 2 mgoodman 2003-04-29 23:22:50 UTC
From: Mark Goodman <mgoodman@CSUA.Berkeley.EDU>
To: bangerth@dealii.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org,
   mgoodman@csua.berkeley.edu, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: c++/10468: Type interpreted as int& instead of const int&
Date: Tue, 29 Apr 2003 23:22:50 -0700

 bangerth@dealii.org wrote:
 
 >Synopsis: Type interpreted as int& instead of const int&
 >
 >State-Changed-From-To: open->feedback
 >State-Changed-By: bangerth
 >State-Changed-When: Wed Apr 23 21:47:56 2003
 >State-Changed-Why:
 >    Why should it be different than what gcc does? Can you
 >    point to a certain paragraph in the standard? I'd think
 >    gcc is right.
 >    
 >    Wolfgang
 >
 >http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10468
 >
 const typeof(x) t1& should be const int & not int & when x is an int.  
 AFAIK, typeof is a gcc extension so no I can't point to a certain 
 paragraph in the ISO C++ standard.  If the template declaration is 
 removed and T is changed to an int, the code works just fine.  I think 
 gcc is broken in this particular case.  I have looked at finish_typeof 
 in gcc/cp/semantics.c but I don't see how to dump the tree  from there.
 
 Mark
 
 
Comment 3 Wolfgang Bangerth 2003-04-30 14:52:04 UTC
State-Changed-From-To: feedback->analyzed
State-Changed-Why: I'm sorry, I just misread the original example and missed
    the const keyword. Indeed, I agree. The problem is best
    exemplified with this snippet:
    --------------------------------
    template <class T>
    void test1() {
      int x = 0;
      const typeof(x) & t1 = x+0;
    }
    
    void test2() {
      int x = 0;
      const typeof(x) & t1 = x+0;
    }
    
    int main() {
      test1<int>();
      test2 ();
    }
    -------------------------
    
    While test2 compiles just fine, test1 doesn't, although
    it's all the same except for the fact that it is a
    template. Here's the message with present 3.4:
    g/x> /home/bangerth/bin/gcc-3.4-pre/bin/bin/c++ -c x.cc
    x.cc: In function `void test1() [with T = int]':
    x.cc:13:   instantiated from here
    x.cc:4: error: could not convert `x' to `int&'
    
    W.
Comment 4 Andrew Pinski 2003-06-14 22:38:35 UTC
Your testcase now compiles on the mainline (20030614). So this only a 3.3 regression.
Comment 5 Andrew Pinski 2003-06-23 23:56:45 UTC
3.2.3 gives the same error message as did 3.0.4.
Comment 7 CVS Commits 2003-06-27 22:46:51 UTC
Subject: Bug 10468

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2003-06-27 22:46:47

Modified files:
	gcc/cp         : ChangeLog pt.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/ext: typeof6.C 

Log message:
	PR c++/10468
	* pt.c (tsubst): Handle qualified TYPEOF_TYPEs correctly.
	
	PR c++/10468
	* g++.dg/ext/typeof5.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3461&r2=1.3462
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.706&r2=1.707
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2810&r2=1.2811
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/typeof6.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 8 Mark Mitchell 2003-06-27 22:47:53 UTC
Fixed in GCC 3.3.1 and GCC 3.4.