[Bug c++/16610] constructor template binding different than plain function for same types
igodard at pacbell dot net
gcc-bugzilla@gcc.gnu.org
Sat Jul 17 22:58:00 GMT 2004
------- Additional Comments From igodard at pacbell dot net 2004-07-17 22:58 -------
There isn't anything in the standard that would cause constructor templates to bind differently than plain functions, is there?
Incidentally, the array call is recognized only on global functions. Member functions and static members all think it's a reference:
#include <iostream>
template<typename T>
void Foo(T t) { std::cout << "any\n"; }
template<typename T>
void Foo(T*const& t) { std::cout << "reference\n"; }
template<typename T, size_t s>
void Foo(T(&t)[s]) { std::cout << "array\n"; }
template<typename T>
struct Frob {
Frob(T*const& t) { std::cout << "reference\n"; }
template<size_t s>
Frob(T(&t)[s]) { std::cout << "array\n"; }
void Bar(T*const& t) { std::cout << "reference\n"; }
template<size_t s>
void Bar(T(&t)[s]) { std::cout << "array\n"; }
static void Baz(T*const& t) { std::cout << "reference\n"; }
template<size_t s>
static void Baz(T(&t)[s]) { std::cout << "array\n"; }
};
int main() {
int* ri;
int ra[10];
Foo(ri);
Foo(ra);
Foo(new int[2]);
Frob<int> f1(ri);
Frob<int> f2(ra);
Frob<int> f3(new int[2]);
Frob<int> f4 = ri;
Frob<int> f5 = ra;
Frob<int> f6 = new int[2];
f1.Bar(ri);
f1.Bar(ra);
Frob<int>::Baz(ri);
Frob<int>::Baz(ra);
}
gives:
~/ootbc/members/members/sweetie/test/src$ a.out
reference
array
reference
reference
reference
reference
reference
reference
reference
reference
reference
reference
reference
Ivan
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16610
More information about the Gcc-bugs
mailing list