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]

c++/635: initializers for static const variables in templates not called



>Number:         635
>Category:       c++
>Synopsis:       initializers for static const variables in templates not called
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Thu Oct 12 12:16:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     narayansl@yahoo.com
>Release:        2.95.2 19991024 (release)
>Organization:
>Environment:
rs6000-ibm-aix4.3.3.0
>Description:
g++ ignores the initialization for a static variable
inside a template if it is a const

Output from the program (attached) should be :
inside Bar::setFlag
inside TFoo1<T>::setFlag
inside TFoo2<T>::setFlag

instead output from g++ compiled version is:
inside Bar::setFlag
inside TFoo2<T>::setFlag
>How-To-Repeat:
#include <iostream.h>

template<typename T> struct TFoo1 {
  static bool setFlag() {
    cout<<"inside TFoo1<T>::setFlag"<<endl;
    return false;
  }
  static const bool flag;
};

template<typename T> struct TFoo2 {
  static bool setFlag() {
    cout<<"inside TFoo2<T>::setFlag"<<endl;
    return false;
  }
  static bool flag;
};


struct Bar {
  static bool setFlag() {
    cout<<"inside Bar::setFlag"<<endl;
    return false;
  }
  static const bool flag;
};

// static variables init
template<typename T> const bool TFoo1<T>::flag(setFlag());
const bool Bar::flag(Bar::setFlag());
template<typename T> bool TFoo2<T>::flag(setFlag());

int
main() {
  // force instance
  TFoo1<int> a; cout<<a.flag;
  TFoo2<int> b; cout<<b.flag;
}

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:

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