public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/45132] New: Inconsistant function overloading between template and non-template functions
@ 2010-07-29 14:48 g_sauthoff at web dot de
2010-07-29 15:18 ` [Bug c++/45132] " pinskia at gcc dot gnu dot org
2010-07-29 15:20 ` pinskia at gcc dot gnu dot org
0 siblings, 2 replies; 3+ messages in thread
From: g_sauthoff at web dot de @ 2010-07-29 14:48 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-07-29 15:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-29 14:48 [Bug c++/45132] New: Inconsistant function overloading between template and non-template functions g_sauthoff at web dot de
2010-07-29 15:18 ` [Bug c++/45132] " pinskia at gcc dot gnu dot org
2010-07-29 15:20 ` pinskia at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).