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++/51494] Legal program rejection - capturing "this" when using static method inside lambda


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51494

Andy Lutomirski <luto at mit dot edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |luto at mit dot edu

--- Comment #2 from Andy Lutomirski <luto at mit dot edu> 2012-05-03 21:53:18 UTC ---
This seems to have gotten worse in gcc 4.7.  This code is now rejected as well:

This code:

struct A
{
  static void func1() {}
};

template<typename T>
struct B : public A
{
  void func2() const
  {
    func3([&]{ func1(); });
  }

  template<typename Func>
  void func3(Func f) const
  {
  }
};

template class B<int>;

The error is:

template_bug.cc: In instantiation of âB<T>::func2() const [with T =
int]::<lambda()>â:
template_bug.cc:11:22:   required from âstruct B<T>::func2() const [with T =
int]::<lambda()>â
template_bug.cc:11:5:   required from âvoid B<T>::func2() const [with T = int]â
template_bug.cc:20:16:   required from here
template_bug.cc:11:16: error: redeclaration of âconst B<int>* const
B<T>::func2() const [with T = int]::<lambda()>::__thisâ
template_bug.cc:11:22: note: previous declaration âconst B<int>* const
B<T>::func2() const [with T = int]::<lambda()>::__thisâ
template_bug.cc:11:16: error: redeclaration of âconst B<int>* const thisâ
template_bug.cc:11:22: error: âconst B<int>* const thisâ previously declared
here
template_bug.cc:15:8: error: âvoid B<T>::func3(Func) const [with Func =
B<T>::func2() const [with T = int]::<lambda()>; T = int]â, declared using local
type âB<T>::func2() const [with T = int]::<lambda()>â, is used but never
defined [-fpermissive]

Your patch fixes this test case, too.


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