Bug 61148 - Cannot access protected members from a lambda capturing this
Summary: Cannot access protected members from a lambda capturing this
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: 5.0
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda
: 61149 (view as bug list)
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2014-05-11 23:08 UTC by Ville Voutilainen
Modified: 2022-03-11 00:32 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ville Voutilainen 2014-05-11 23:08:57 UTC
Test:

class DB {
        protected:
        void foo() {};
};
class DC : public DB {
        public:
        DC() {
                [this]() {
                        DB::foo(); // #1
                }();
        };
};

int main(void)
{
        DC x;
}

This is potentially a duplicate of
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58972

Clang accepts the code. gcc prints

lambda-protected.cpp: In lambda function:
lambda-protected.cpp:3:14: error: ‘void DB::foo()’ is protected
         void foo() {};
              ^
lambda-protected.cpp:9:33: error: within this context
                         DB::foo();
                                 ^

And changing #1 to this->DB::foo(); does not help.
Comment 1 Jan Engelhardt 2014-05-11 23:16:40 UTC
Definitely a duplicate of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61149 ;)
Comment 2 Ville Voutilainen 2014-05-11 23:17:43 UTC
Most likely caused by the same problem as http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59483
Comment 3 Paolo Carlini 2014-05-12 08:28:41 UTC
*** Bug 61149 has been marked as a duplicate of this bug. ***
Comment 4 Jason Merrill 2014-06-02 20:48:27 UTC
Author: jason
Date: Mon Jun  2 20:47:55 2014
New Revision: 211147

URL: http://gcc.gnu.org/viewcvs?rev=211147&root=gcc&view=rev
Log:
	PR c++/59483
	PR c++/61148
	* search.c (accessible_p): Use current_nonlambda_class_type.
	* semantics.c (check_accessibility_of_qualified_id): Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-59483.C
    trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-61148.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/search.c
    trunk/gcc/cp/semantics.c
Comment 5 Jason Merrill 2014-06-09 19:25:29 UTC
Fixed on trunk.