Consider following test-case:

$ cat templorder.cc
#include <iostream>

struct Foo {
  int a;
  char b;
};

template<typename T> inline int match(const T &x)
{
  return 23;
}

template <typename T> inline int not_match(const T &x)
{
  return match(x) + 1;
}

template <> inline int match<int>(const int &x)
{
  return 42;
}

inline int match(const Foo & x)
{
  return 52;
}

inline int match(const double &d)
{
  return 62;
}


#define CHECK_EQ(A, B) if (!((A) == (B))) { ++r; std::cerr << "Error: " << (A)
<< " != " << (B) << '\n'; }

int main()
{
  int r = 0;

  int i = 0;
  CHECK_EQ(not_match(i), 43);
  char c = 0;
  Foo f;
  CHECK_EQ(not_match(f), 53);

  double d = 0;

  // BANG
  CHECK_EQ(not_match(d), 63);

  return r;
}
$ g++ temporder.cc
$ ./a.out
Error: 24 != 63

This behavior is inconsistant, because either 'CHECK_EQ(not_match(f), 53)'
should fail, too or 'CHECK_EQ(not_match(d), 63)' should not fail.

I would expect that 'CHECK_EQ(not_match(d), 63)' should not fail. But perhaps I
am missing some rule in the C++ standard.

Compiling the test case with the C++ Sun Workshop Pro CC and executing prints
no errors.

$ cat /etc/issue
Ubuntu 10.04.1 LTS

But I got the same output with g++ under the previous two Ubuntu versions.


-- 
           Summary: Inconsistant function overloading between template and
                    non-template functions
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: g_sauthoff at web dot de


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

Reply via email to