------- Additional Comments From bangerth at dealii dot org  2005-07-08 14:58 
-------
I don't quite know what to say, whether this is a bug or not. Take 
this reduced snippet: 
--------------------------- 
template <class T> struct S { 
    friend void foo(T *); 
}; 
 
template <class T> void bar() { foo((T*)0); } 
 
template <class T> 
struct X : S< X<T> > 
{ 
    X() { bar<T>(); } 
}; 
 
X< X<int> > test; 
---------------------------- 
icc compiles this, but gcc doesn't, with this error message: 
 
g/x> /home/bangerth/bin/gcc-4.1*/bin/c++ -c x.cc 
x.cc:2: warning: friend declaration &#8216;void foo(T*)&#8217; declares a 
non-template 
function 
x.cc:2: warning: (if this is not what you intended, make sure the function 
template has already been declared and add <> after the function name here) 
-Wno-non-template-friend disables this warning 
x.cc: In function &#8216;void bar() [with T = X<int>]&#8217;: 
x.cc:10:   instantiated from &#8216;X<T>::X() [with T = X<int>]&#8217; 
x.cc:13:   instantiated from here 
x.cc:5: error: cannot convert &#8216;X<int>*&#8217; to &#8216;X<X<int> 
>*&#8217; for argument &#8216;1&#8217; to 
&#8216;void foo(X<X<int> >*)&#8217; 
 
What is happening is that in the definition of 'test', we instantiate 
X<X<int> >, which through its derivation from S<X<X<int>>> makes sure  
that there is a function foo<X<X<int>>> (that this function is available 
is visible from the error message). However, in the destructor of 
X<X<int>>, we call bar<X<int>> which in turn wants to call foo<X<int>>, 
which doesn't exist. 
 
I believe that the reason why icc can compile this is that in the definition 
of 'test', the compiler does not only instantiate X<X<int>>, but also X<int>. 
If that were the case, then we would have a function foo<X<int>> from that 
instantiation, available for use when we get to instantiate the destructor 
of X<X<int>>. The question is: do we need to instantiate X<int> in order to 
instantiate X<X<int>>? 
 
(Here's a sidenote: apparently, icc only instantiates the *type* X<int>, 
but not the destructor X<int>::~X. I can infer this because if it did, 
then it would want to call bar<int> which in turn would want to call 
foo<int>; that one, however, doesn't exist...) 
 
W. 

-- 


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

Reply via email to