This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Template not instantiated (or recognized to match?)


Hmmpf, I don't know how to correctly describe what goes wrong
here :). The problem is that no match is found for a template
function, while it should imho.

Please consider the following code:

------------------------------------------------------------------------
class ostream {} cout;	// Blah
class Foo {};		// Arbitrary class.

typedef int A1;		// Case 1: use an int.
A1 const p1 = 0;	// Template parameter: a constant int.

typedef Foo& A2;	// Case 2: use a reference to some class Foo.
extern Foo p2;		// Template parameter: a Foo with external linkage.

template<A1 tp>		// Class B1 uses `int' as template parameter.
  class B1 {};

template<A2 tp>		// Class B2 uses `Foo const&' as template parameter.
  class B2 {};

B1<p1> b1;		// Define a B1<p1>

B2<p2> b2;		// Define a B2<p2>

// Define two templated operator<<:

template<A1 tp>
  ostream& operator<<(ostream&, B1<tp> const& x) { }

template<A2 tp>
  ostream& operator<<(ostream&, B2<tp> const& x) { }


int main(void)
{
  // Try calling case 1:
  operator<<(cout, b1);		// OK
  cout << b1;			// OK

  // Try calling case 2:
  operator<<(cout, b2);		// COMPILE ERROR
  cout << b2;			// COMPILE ERROR

  return 0;
}
------------------------------------------------------------------------

This results in the following compile error:

~/c++/libcw/src/gcc.bugs>g++-cvs -v -c 20000329.cc
Reading specs from /usr/local/egcs/lib/gcc-lib/i686-pc-linux-gnu/2.96/specs
gcc version 2.96 20000322 (experimental)
 /usr/local/egcs/lib/gcc-lib/i686-pc-linux-gnu/2.96/cpp -lang-c++ -v -iprefix /usr/local/bin/../lib/gcc-lib/i686-pc-linux-gnu/2.96/ -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=96 -D__GNUC_PATCHLEVEL__=0 -D__cplusplus -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__tune_pentiumpro__ 20000329.cc /tmp/ccdQGGdp.ii
GNU CPP version 2.96 20000322 (experimental) (cpplib)
 (i386 Linux/ELF)
ignoring nonexistent directory `/usr/local/include/g++-3'
ignoring nonexistent directory `/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.96/include'
ignoring nonexistent directory `/usr/local/i686-pc-linux-gnu/include'
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/egcs/include/g++-3
 /usr/local/egcs/include
 /usr/local/egcs/lib/gcc-lib/i686-pc-linux-gnu/2.96/include
 /usr/local/egcs/i686-pc-linux-gnu/include
 /usr/include
End of search list.
 /usr/local/egcs/lib/gcc-lib/i686-pc-linux-gnu/2.96/cc1plus /tmp/ccdQGGdp.ii -quiet -dumpbase 20000329.cc -version -o /tmp/cc4RbhtD.s
GNU C++ version 2.96 20000322 (experimental) (i686-pc-linux-gnu) compiled by GNU C version 2.95.1 19990816/Linux (release).
20000329.cc: In function `int main ()':
20000329.cc:36: no matching function for call to `operator<< (ostream&,
20000329.cc:36: B2<p2>&)'
20000329.cc:37: no match for `ostream& << B2<p2>&'


Regards,

-- 
Carlo Wood <carlo@alinoe.com>

PS Am I still the one who found the most template bugs? :)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]