This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/16610] constructor template binding different than plain function for same types


------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]