Bug 13323 - [3.3/3.4 regression] Template code does not compile in presence of typedef
Summary: [3.3/3.4 regression] Template code does not compile in presence of typedef
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.2
: P2 normal
Target Milestone: 3.3.3
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2003-12-05 21:01 UTC by David M. Lee
Modified: 2004-01-17 04:22 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux
Target: i686-pc-linux
Build: i686-pc-linux
Known to work:
Known to fail:
Last reconfirmed: 2003-12-05 21:12:51


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David M. Lee 2003-12-05 21:01:49 UTC
The following code compiles fine with gcc 3.2.  However, with 3.3.2, I get an 
error.

[dlee@d100-devel cpp]$ cat > bug.cpp <<EOF
typedef int INT_TYPEDEF;

template<class T>
class TypedIfc
{
public:
  virtual ~TypedIfc() { }
  virtual operator const T&() const = 0;
  virtual const T& operator= (const T& t) = 0;
};

template<class Tnative>
class NullIfc : public TypedIfc<Tnative>
{
public:
  const Tnative& operator= (const Tnative& t) { return t; }
  operator const Tnative&() const { return *(Tnative *)0; }
};

#ifndef DONTBREAK // -DDONTBREAK to get a build that works.
typedef TypedIfc<INT_TYPEDEF> INT_TYPEDEFIfc;
#endif

NullIfc<int> i32;
EOF

[dlee@d100-devel cpp]$ i686-linux-g++ bug.cpp -o /dev/null -c -DDONTBREAK
[dlee@d100-devel cpp]$ i686-linux-g++ bug.cpp -o /dev/null -c
bug.cpp:24: error: cannot declare variable `i32' to be of type `NullIfc<int>'
bug.cpp:24: error:   because the following virtual functions are abstract:
bug.cpp:8: error:       TypedIfc<T>::operator const T&() const [with T = 
   INT_TYPEDEF]

Here's the info for my compiler:

[dlee@d100-devel cpp]$ i686-linux-g++ --verbose
Reading specs from /tools/i386/lib/gcc-lib/i686-linux/3.3.2/specs
Configured with: /src/gcc-3.3.2/configure --target=i686-linux --host=i686-
host_pc-linux-gnu --prefix=/tools/i386 --with-headers=/tools/i386/i686-
linux/include --disable-nls --enable-symvers=gnu --enable-threads=posix --
enable-__cxa_atexit --enable-languages=c,c++ --enable-clocale=gnu --with-local-
prefix=/home/dlee/vcs/Products/Breeze/Dev/Prj/LinuxRH8/tscale2/tools/i386/i686-
linux --disable-multilib
Thread model: posix
gcc version 3.3.2
Comment 1 Wolfgang Bangerth 2003-12-05 21:12:50 UTC
This is clearly a bug, and a regression on 3.3/mainline w.r.t. 3.2.x. 
 
Here's an extract: 
------------------------- 
template <class T> struct B { 
  virtual operator T() const = 0; 
}; 
 
template <class T> 
struct D : B<T> { 
  virtual operator T() const; 
}; 
 
typedef int i; 
typedef B<i> Bi; 
 
D<int> i32; 
--------------------------- 
 
g/x> /home/bangerth/bin/gcc-3.2.3/bin/c++ -c x.cc 
g/x> /home/bangerth/bin/gcc-3.3.3-pre/bin/c++ -c x.cc 
x.cc:13: error: cannot declare variable `i32' to be of type `D<int>' 
x.cc:13: error:   because the following virtual functions are abstract: 
x.cc:2: error:  B<T>::operator T() const [with T = i] 
 
W. 
Comment 2 Andrew Pinski 2003-12-06 02:46:20 UTC
From Phil's regression hunter: Search converges between 2003-06-17-trunk (#316) and 2003-06
-18-trunk (#317).
: Search converges between 2003-06-14-3.3 (#145) and 2003-06-22-3.3 (#146).

Related to bug 11928 and PR 11713 (the ones caused also in the same time period, both of them 
the same patch).
So it is most likely the same patch:
2003-06-17  Mark Mitchell  <mark@codesourcery.com>

      PR c++/11105
      * cp-tree.h (DECL_CONV_FN_TYPE): New method.
      * decl.c (lookup_name_real): Backport conversion operator code
      from mainline.
      * mangle.c (struct globals): Remove internal_mangling_p.
      (write_unqualified_name): Use DECL_CONV_FN_TYPE.
      (write_template_parm): Don't write out the level number.
      (conv_type_names): New variable.
      (hash_type): New function.
      (compare_type): Likewise.
      (mangle_conv_op_name_for_type): Don't try to mangle conversion
      operator names.
      * search.c (lookup_conversion_operator): New function.
      (lookup_fnfields_1): Use it.

Mark could you look at this one?
Comment 3 CVS Commits 2003-12-06 22:11:52 UTC
Subject: Bug 13323

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

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

Log message:
	PR c++/13323
	* class.c (same_signature_p): Handle conversion operators
	correctly.
	(check_for_override): Likewise.
	
	PR c++/13323
	* g++.dg/inherit/operator2.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3785&r2=1.3786
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&r1=1.583&r2=1.584
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3234&r2=1.3235
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/inherit/operator2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 4 CVS Commits 2003-12-06 22:19:34 UTC
Subject: Bug 13323

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	mmitchel@gcc.gnu.org	2003-12-06 22:19:31

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

Log message:
	PR c++/13323
	* class.c (same_signature_p): Handle conversion operators
	correctly.
	(check_for_override): Likewise.
	
	PR c++/13323
	* g++.dg/inherit/operator2.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.221&r2=1.3076.2.222
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.499.2.24&r2=1.499.2.25
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.324&r2=1.2261.2.325
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/inherit/operator2.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1

Comment 5 Mark Mitchell 2003-12-06 22:20:17 UTC
Fixed in GCC 3.3.3 and GCC 3.4.
Comment 6 David M. Lee 2003-12-08 22:17:10 UTC
Thanks for the prompt response!  This fix gets me going again :-)