https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70218

            Bug ID: 70218
           Summary: Illegal access to private fields succeeds with 5/6
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: doko at gcc dot gnu.org
  Target Milestone: ---

[forwarded from https://bugs.debian.org/816366]

$ cat foo.cc 
#include <thread>
class X {
    int i;
};
main() {
    X x;
    std::thread([&x] { x.i = 3; });
}

g++-4.9 detects access to X::i which is private. Only happens in the specific
combination of a new thread and the lambda expression. g++-5 and g++-6 accept
this.

$ g++-4.9 -std=gnu++11 foo.cc
foo.cc: In lambda function:
foo.cc:3:9: error: 'int X::i' is private
     int i;
         ^
foo.cc:7:26: error: within this context
     std::thread([&x] { x.i = 3; });
                          ^

Reply via email to