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++/12222] explicit initialization of static template members seems ignored


------- Additional Comments From bangerth at dealii dot org  2004-08-16 18:37 -------
gcc's behavior actually makes a lot more sense than anyone seems to 
have noticed: with this code 
---------------- 
template <typename T> 
struct a { static int b1; }; 
 
template struct a<float>; 
template <> int a<float>::b1; 
 
int x = a<float>::b1; 
----------------- 
we indeed get no warning that a specialization is declared after  
instantiating the template. However, that's about ok: we haven't 
provided a definition of the static member, so it isn't instantiated 
and the declaration of the specialization doesn't come too late. 
 
On the other hand, for this code (not the presence of the definition) 
------------------ 
template <typename T> 
struct a { static int b1; }; 
template <typename T> int a<T>::b1; 
 
template struct a<float>; 
template <> int a<float>::b1; 
 
int x = a<float>::b1; 
------------------ 
we _do_ get an error: 
 
g/x> /home/bangerth/bin/gcc-3.5-pre/bin/c++ -Wall -c x.cc 
x.cc:6: error: redefinition of `int a<float>::b1' 
x.cc:3: error: `int a<float>::b1' previously declared here 
 
I think gcc is correct here. So closing. 
 
W. 

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


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


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