Bug 45132 - Inconsistent function overloading between template and non-template functions
Summary: Inconsistent function overloading between template and non-template functions
Status: RESOLVED DUPLICATE of bug 29131
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-29 14:47 UTC by Georg Sauthoff
Modified: 2010-07-29 17:33 UTC (History)
11 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Georg Sauthoff 2010-07-29 14:47:57 UTC
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.
Comment 1 Andrew Pinski 2010-07-29 15:17:54 UTC
>But perhaps I am missing some rule in the C++ standard.

Yes you are.  You are missing that fundamental types in C++ don't have an associated namespace.
Comment 2 Andrew Pinski 2010-07-29 15:19:47 UTC

*** This bug has been marked as a duplicate of 29131 ***