This is the mail archive of the gcc-help@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]
Other format: [Raw text]

Postincrement causes match problem - bug or feature?


Hi,

The following code gives a function match error.  If the postincrement
is removed on cp when calling foo(), everything is fine.  Is this a
compiler problem or a user problem?

Thanks:

=================

#include <iostream>

using namespace std;

template <typename T>
int foo(T& t1)
{
  cerr << "Got in #1!\n";
  return 0;
}

int foo(char* & c)
{
  cerr << "Got in #2!\n";
  return 0;
}

int main()
{
  char c = 'c';
  char* cp = &c;

  foo(cp++);
  return (0);
}

==============

test2.cc: In function 'int main()':
test2.cc:23: error: no matching function for call to 'foo(char*)'
test2.cc:6: note: candidates are: int foo(T&) [with T = char*]
test2.cc:12: note:                 int foo(char*&)

==============

$ gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada
--enable-java-awt=gtk --disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre
--with-cpu=generic --host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.2 20070626 (Red Hat 4.1.2-14)

-- 
Andrew Bell
andrew.bell.ia@gmail.com


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