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
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
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
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.
Your testcase now compiles on the mainline (20030614). So this only a 3.3 regression.
3.2.3 gives the same error message as did 3.0.4.
Subject: Bug 10468 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: mmitchel@gcc.gnu.org 2003-06-27 22:43:48 Modified files: gcc/cp : ChangeLog pt.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/ext: typeof5.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&only_with_tag=gcc-3_3-branch&r1=1.3076.2.166&r2=1.3076.2.167 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.635.2.30&r2=1.635.2.31 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.206&r2=1.2261.2.207 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/typeof5.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.8.1
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
Fixed in GCC 3.3.1 and GCC 3.4.