------- Additional Comments From bangerth at dealii dot org  2004-10-13 12:50 -------
I'm not sure this is a bug: the standard quite unmistakably says that 
default arguments aren't evaluated unless used. Now, if I try to 
use the default argument in your testcase, like so 
------------------ 
template<typename> struct A {}; 
 
template<typename T> struct B 
{ 
    A<T> a; 
 
    void foo(A<T> = a); 
}; 
 
void bar () 
{ 
  B<int>().foo(); 
} 
-------------------------- 
then I do get a sensible error: 
g/x> /home/bangerth/bin/gcc-4.0-pre/bin/c++ -c x.cc 
x.cc:5: error: invalid use of non-static data member `B<int>::a' 
x.cc:12: error: from this location 
 
Can you say why the compiler should diagnose this earlier rather than 
later, given what the standard says? 
 
For reference: 
14.7.2/9 says 
  An explicit instantiation does not  constitute  a  use  of  a  default 
  argument, so default argument instantiation is not done.  [Example: 
 
     char* p = 0; 
     template<class T> T g(T = &p); 
     template int g<int>(int);       // OK even though &p isn't an int. 
 
   --end example] 
and there are more places like this. 
 
W. 

-- 


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

Reply via email to