This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/52688] static local variable can accessed from local class of function template


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]