This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/33061] New: Static variable typed the member type of another class
- From: "kag at graf dot slask dot pl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 13 Aug 2007 15:11:12 -0000
- Subject: [Bug c++/33061] New: Static variable typed the member type of another class
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
// this c++ code failes to compile under every gcc/g++ version I know...
#include<map>
template<class T>
class foo
{
private:
static std::map<long, std::pair<T, long> > data;
static long long lastId;
public:
foo ()
{
refValid = false;
}
foo (const T & v)
{
lastId++;
ref = data.insert
(std::pair<long, std::pair<T, long> > (lastId,
std::pair<T, long> (v, 0))).first;
refValid = true;
(*ref).second.second++;
}
foo (const foo<T> & v)
{
operator= (v);
}
~foo ()
{
end ();
}
void operator= (const foo<T> & v)
{
if (&v == this) return;
end ();
ref = v.ref;
refValid = true;
(*ref).second.second++;
}
private:
// g++ fails here:
std::map<long, std::pair<T, long> >::iterator ref;
bool refValid;
void end ()
{
if (!refValid) return;
(*ref).second.second--;
refValid = false;
}
};
template<class T>
std::map<long, std::pair<T, long> > foo<T>::data;
template<class T>
long long foo<T>::lastId = 0;
int main ()
{
foo<char> x;
return 0;
}
--
Summary: Static variable typed the member type of another class
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: kag at graf dot slask dot pl
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33061