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

narayansl@yahoo.com narayansl@yahoo.com
Thu Oct 12 12:16:00 GMT 2000


>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:


More information about the Gcc-bugs mailing list