This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/635: initializers for static const variables in templates not called
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/635: initializers for static const variables in templates not called
- From: narayansl at yahoo dot com
- Date: 12 Oct 2000 19:07:20 -0000
- Reply-To: narayansl at yahoo dot com
- Resent-Cc: gcc-prs at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org, jason at gcc dot gnu dot org
- Resent-Reply-To: gcc-gnats@gcc.gnu.org, narayansl@yahoo.com
>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: