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: "jared.cantwell at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 01 Mar 2013 23:18:23 +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
--- Comment #11 from jared.cantwell at gmail dot com 2013-03-01 23:18:23 UTC ---
(In reply to comment #9)
> (In reply to comment #8)
> > I just came across the same issue in the context of lambdas (for posterity,
> > since I spent time thinking this was specific to lambdas).
> >
> > Consider the following source code:
> > ---------------------------------------------------
> > template<typename T>
> > void Foo()
> > {
> > static int i = 5;
> > auto bar = [&]() { ++i; };
> > bar();
> > }
> >
> > int main()
> > {
> > Foo<int>();
> > }
> > ---------------------------------------------------
> > GCC 4.7.0 produces the following error:
> >
> > # g++-4.7 -std=c++11 main.cpp
> > /tmp/ccbZwBzT.o: In function `void Foo<int>()::{lambda()#1}::operator()()
> > const':
> > main.cpp:(.text+0x1a): undefined reference to `i'
> > main.cpp:(.text+0x23): undefined reference to `i'
> > collect2: error: ld returned 1 exit status
>
> Can't be exactly the same issue: mainline and 4.7.3 get this one right.
It seems my comment is more aligned with
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54276 then this case.