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]
Other format: [Raw text]

[Bug c++/12423] New: Function template fails to match


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12423

           Summary: Function template fails to match
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mj1 at cog dot brown dot edu
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: 3.3.1
GCC target triplet: i686-pc-linux-gnu

A function template that matched in earlier versions of g++ (specifically 3.2.2)
fails to match in g++ 3.3.1

An example which indicates this is very simple:

/////////////////////////////////////////////////////////////
//
// wont-compile-with-g++3.3.1.cc
//
// Mark Johnson, 11th September 2003
//
// This program compiles qute happily with old g++ versions
// (e.g., g++ (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5))
// but fails to compile with g++ (GCC) 3.3.1.
//
// g++     wont-compile-with-g++3.3.1.cc   -o wont-compile-with-g++3.3.1
// wont-compile-with-g++3.3.1.cc: In function `int main(int, char**)':
// wont-compile-with-g++3.3.1.cc:40: error: no matching function for call to `
//    afind(std::map<int, int, std::less<int>, std::allocator<std::pair<const int, 
//    int> > >&, int&)'

#include <cassert>
#include <iostream>
#include <map>

// afind(map, key) returns a reference to the value associated
//  with key in map.  It uses assert to check that the key's value
//  is defined.
//
template <typename Map, typename Key>
typename Map::data_type& afind(Map& m, const Key& k)
{
  typename Map::iterator i = m.find(k);
  assert(i != m.end());
  return i->second;
}


int main(int argc, char** argv) 
{
  std::map<int,int> m;

  for (int i = 1; i < 10; ++i)
    m[i] = i*i;

  for (int i = 1; i < 10; ++i)
    std::cout << "m[" << i << "] = " << afind(m, i) << std::endl;
}

/////////////////////////////////////////////////////////////

cd /home/mj/C++/g++-3.3.1-errors/
make 
g++ -v -save-temps    wont-compile-with-g++3.3.1.cc   -o wont-compile-with-g++3.3.1
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/specs
Configured with: ../gcc-3.3.1/configure --with-cpu=pentium4 --with-arch=pentium4
--with-tune=pentium4 --enable-languages=c,c++,f77,java
Thread model: posix
gcc version 3.3.1
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/cc1plus -E -D__GNUG__=3 -quiet
-v -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=1 -D_GNU_SOURCE
wont-compile-with-g++3.3.1.cc wont-compile-with-g++3.3.1.ii
ignoring nonexistent directory "NONE/include"
ignoring nonexistent directory "/usr/local/i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include/c++/3.3.1
 /usr/local/include/c++/3.3.1/i686-pc-linux-gnu
 /usr/local/include/c++/3.3.1/backward
 /usr/local/include
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/include
 /usr/include
End of search list.
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/cc1plus -fpreprocessed
wont-compile-with-g++3.3.1.ii -quiet -dumpbase wont-compile-with-g++3.3.1.cc
-auxbase wont-compile-with-g++3.3.1 -version -o wont-compile-with-g++3.3.1.s
GNU C++ version 3.3.1 (i686-pc-linux-gnu)
	compiled by GNU C version 3.3.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
wont-compile-with-g++3.3.1.cc: In function `int main(int, char**)':
wont-compile-with-g++3.3.1.cc:40: error: no matching function for call to `
   afind(std::map<int, int, std::less<int>, std::allocator<std::pair<const int, 
   int> > >&, int&)'
make: *** [wont-compile-with-g++3.3.1] Error 1

Compilation exited abnormally with code 2 at Fri Sep 26 13:28:49


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