This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/16610] constructor template binding different than plain function for same types
- From: "bangerth at dealii dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 Jul 2004 13:54:50 -0000
- Subject: [Bug c++/16610] constructor template binding different than plain function for same types
- References: <20040717210303.16610.igodard@pacbell.net>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From bangerth at dealii dot org 2004-07-19 13:54 -------
This doesn't have anything to do with constructors vs global functions.
Here's another testcase:
----------------------
#include <iostream>
struct Frob1 {
template<typename T>
Frob1 (T * const& t) { std::cout << "reference\n"; }
template<typename T, size_t s>
Frob1 (T (&t)[s]) { std::cout << "array\n"; }
};
template <typename T>
struct Frob2 {
Frob2 (T * const& t) { std::cout << "reference\n"; }
template<size_t s>
Frob2 (T (&t)[s]) { std::cout << "array\n"; }
};
int main() {
int ra[10];
Frob1 f1(ra);
Frob2<int> f2(ra);
}
---------------------------
Note how Frob1 has no outer template, but templates on the constructors,
while Frob2 gets its T type from an outer template.
We get this output with all compilers I have:
g/x> /home/bangerth/bin/gcc-3.5-pre/bin/c++ x.cc ; ./a.out
array
reference
Why that is so, someone else will have to explain, but I assume it is correct.
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16610