[Bug c++/14500] New: most specialized function template vs. non-template function

bkoz at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Tue Mar 9 04:51:00 GMT 2004


While working on c++/13658, I ran into divergent behavior between icc 7.1 and g++.

I think g++ is wrong, and that in the code below, the explicitly specialized
function template is the most specialized function, and should be called.

By removing the template specialization syntax (ie "template<>"), and trying
again, I get something that is considered the most specialized. But, why this
and not the other?

-benjamin

#include <vector>
#include <cassert>
#define VERIFY assert
 
struct T { int i; };

int swap_calls;

namespace std
{
  // Should be most specialized.
#if 1
  template<> 
#endif
    inline void 
    swap(vector<T, allocator<T> >&, vector<T, allocator<T> >&) 
    { ++swap_calls; }
}

void test01()
{
  bool test __attribute__((unused)) = true;
  std::vector<T> A;
  std::vector<T> B;
  swap_calls = 0;
  std::swap(A, B);
  VERIFY(1 == swap_calls); // XXX fails
}

void test02()
{
  bool test __attribute__((unused)) = true;
  using namespace std;
  vector<T> A;
  vector<T> B;
  swap_calls = 0;
  swap(A, B);
  VERIFY(1 == swap_calls);
}

int main()
{
  test01();
  test02();
  return 0;
}

-- 
           Summary: most specialized function template vs. non-template
                    function
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bkoz at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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



More information about the Gcc-bugs mailing list