public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58972] New: Lambda can't access private members
@ 2013-11-02 15:53 akim.demaille at gmail dot com
  2013-11-03 14:53 ` [Bug c++/58972] " daniel.kruegler at googlemail dot com
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: akim.demaille at gmail dot com @ 2013-11-02 15:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 58972
           Summary: Lambda can't access private members
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: akim.demaille at gmail dot com

Hi all,

Again, this problem report might be bogus.  IANALL and reading the proposed
standard did not really help me understand if the problem is in the compiler,
or in the eye of the beholder.

Anyway, I think that if this is not a problem of G++, it is one of C++.  At
least Clang++ (3.4) accepts it.

$ cat foo.cc
class base
{
protected:
  using type = int;
};

template <typename T>
class derive: public base
{
  using typename base::type;
public:
  void foo(type a)
  {
    auto f = [a](type x){ return x == a; };
    f(32);
  }
};

int main()
{
  derive<char> d;
  d.foo(23);
}
$ clang++-mp-3.4 -std=c++11 foo.cc
$ g++-mp-4.9 --version
g++-mp-4.9 (MacPorts gcc49 4.9-20130915_0) 4.9.0 20130915 (experimental)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++-mp-4.9 -std=c++11 foo.cc
foo.cc: In instantiation of 'struct derive<T>::foo(base::type) [with T = char;
base::type = int]::<lambda(using type = int)>':
foo.cc:14:42:   required from 'void derive<T>::foo(base::type) [with T = char;
base::type = int]'
foo.cc:22:11:   required from here
foo.cc:4:19: error: 'using type = int' is protected
   using type = int;
                   ^
foo.cc:14:18: error: within this context
     auto f = [a](type x){ return x == a; };
                  ^
$ g++-mp-4.8 --version
g++-mp-4.8 (MacPorts gcc48 4.8.1_3) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++-mp-4.8 -std=c++11 foo.cc
foo.cc: In instantiation of 'struct derive<T>::foo(base::type) [with T = char;
base::type = int]::__lambda0':
foo.cc:14:42:   required from 'void derive<T>::foo(base::type) [with T = char;
base::type = int]'
foo.cc:22:11:   required from here
foo.cc:4:19: error: 'using type = int' is protected
   using type = int;
                   ^
foo.cc:14:18: error: within this context
     auto f = [a](type x){ return x == a; };
                  ^

FWIW, if derived is no longer template, it works.

BTW, someone should have a look at this:
http://stackoverflow.com/questions/11933999/why-is-it-not-possible-to-use-private-method-in-a-lambda
(and especially http://ideone.com/DJezf).  Maybe it's the same issue, maybe
it's slightly different, but again, clang++ eats it.


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2015-08-21 16:01 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-02 15:53 [Bug c++/58972] New: Lambda can't access private members akim.demaille at gmail dot com
2013-11-03 14:53 ` [Bug c++/58972] " daniel.kruegler at googlemail dot com
2014-06-03 21:23 ` ville.voutilainen at gmail dot com
2014-06-03 21:29 ` ville.voutilainen at gmail dot com
2014-06-26 11:13 ` akim.demaille at gmail dot com
2014-06-26 11:44 ` redi at gcc dot gnu.org
2014-06-26 11:55 ` ville.voutilainen at gmail dot com
2014-06-26 12:11 ` daniel.kruegler at googlemail dot com
2014-11-12  9:31 ` ville.voutilainen at gmail dot com
2014-11-12  9:33 ` ville.voutilainen at gmail dot com
2015-06-11 10:48 ` ville.voutilainen at gmail dot com
2015-08-21 11:14 ` ville.voutilainen at gmail dot com
2015-08-21 16:01 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).