This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52688] static local variable can accessed from local class of function template
- From: "daniel.kruegler at googlemail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 16 Jan 2013 09:03:56 +0000
- Subject: [Bug c++/52688] static local variable can accessed from local class of function template
- Auto-submitted: auto-generated
- References: <bug-52688-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52688
Daniel KrÃgler <daniel.kruegler at googlemail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |daniel.kruegler at
| |googlemail dot com
--- Comment #7 from Daniel KrÃgler <daniel.kruegler at googlemail dot com> 2013-01-16 09:03:56 UTC ---
I stumbled across a similar problem recently within a member function of a
class template:
//----------------------------
template<class T>
struct A {
static bool test() {
static bool value = false;
if (value)
return false;
struct S {
S() { value = true; }
};
static S s;
return true;
}
};
int main()
{
A<int>::test();
}
//----------------------------
"obj\Debug\main.o||In function `A<int>::test()::S::S()':|
main.cpp|8|undefined reference to `value'"
It doesn't occur if A is not a template.
I can confirm the error with gcc 4.7.2 and gcc 4.8.0 20130113 (experimental)
compiled with the flags
-Wall -pedantic-errors