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++/16053] Fails to identify overload


------- Additional Comments From bangerth at dealii dot org  2004-06-18 14:00 -------
(You should really learn to write _small_ testcases -- you'd save 
everyone a lot of time that way...) 
 
Here's a reduced testcase: 
---------------------- 
class B {}; 
 
template <typename> struct A { 
    template <typename U> 
    friend void operator<< (A &, const U &); 
}; 
 
template<typename T> 
void operator<<(A<T> &, const B &); 
 
int main() { 
  A<int> d; 
  d << B(); 
} 
----------------------------- 
 
With gcc, we get this error: 
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ -w -c x.cc 
x.cc: In function `int main()': 
x.cc:13: error: ambiguous overload for 'operator<<' in 'd << B()' 
x.cc:9: note: candidates are: void operator<<(A<T>&, const B&) [with T = int] 
x.cc:5: note:                 void operator<<(A< <template-parameter-1-1> >&, 
const U&) [with U = B, <template-parameter-1-1> = int] 
 
I think gcc is completely correct in printing this error: both functions 
are exact matches, but only after template parameter unification. Why do 
you think that gcc should accept the code? 
 
W. 
 
 
PS: With icc, we get this: 
g/x> icc -c -Xc -ansi x.cc 
x.cc(13): error: more than one operator "<<" matches these operands: 
            function template "operator<<(A<int> &, const U &)" 
            function template "operator<<(A<T> &, const B &)" 
            operand types are: A<int> << B 
    d << B(); 
      ^ 
 
compilation aborted for x.cc (code 2) 
 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16053


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