From adb50dfbf65b5a8ac29bed8edd752535e6fd4a35 Mon Sep 17 00:00:00 2001 From: Ville Voutilainen Date: Mon, 2 Jun 2014 23:47:55 +0300 Subject: [PATCH] re PR c++/59483 (A nested lambda fails to find a protected name with qualified name) PR c++/59483 PR c++/61148 * search.c (accessible_p): Use current_nonlambda_class_type. * semantics.c (check_accessibility_of_qualified_id): Likewise. From-SVN: r211147 --- gcc/cp/ChangeLog | 7 ++++ gcc/cp/search.c | 6 ++-- gcc/cp/semantics.c | 5 +-- .../g++.dg/cpp0x/lambda/lambda-59483.C | 31 +++++++++++++++++ .../g++.dg/cpp0x/lambda/lambda-61148.C | 33 +++++++++++++++++++ 5 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-59483.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-61148.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 346782e623b..9b439a964b5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2014-06-02 Ville Voutilainen + + PR c++/59483 + PR c++/61148 + * search.c (accessible_p): Use current_nonlambda_class_type. + * semantics.c (check_accessibility_of_qualified_id): Likewise. + 2014-06-02 Andrew MacLeod * decl.c: Include builtins.h. diff --git a/gcc/cp/search.c b/gcc/cp/search.c index c3eed90f6c3..424b26cd3e1 100644 --- a/gcc/cp/search.c +++ b/gcc/cp/search.c @@ -917,9 +917,11 @@ accessible_p (tree type, tree decl, bool consider_local_p) /* Figure out where the reference is occurring. Check to see if DECL is private or protected in this scope, since that will determine whether protected access is allowed. */ - if (current_class_type) + tree ct = current_nonlambda_class_type (); + if (ct) protected_ok = protected_accessible_p (decl, - current_class_type, binfo); + ct, + binfo); /* Now, loop through the classes of which we are a friend. */ if (!protected_ok) diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 4c13e9dc739..21920b41ca5 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1836,10 +1836,11 @@ check_accessibility_of_qualified_id (tree decl, /* If the reference is to a non-static member of the current class, treat it as if it were referenced through `this'. */ + tree ct; if (DECL_NONSTATIC_MEMBER_P (decl) && current_class_ptr - && DERIVED_FROM_P (scope, current_class_type)) - qualifying_type = current_class_type; + && DERIVED_FROM_P (scope, ct = current_nonlambda_class_type ())) + qualifying_type = ct; /* Otherwise, use the type indicated by the nested-name-specifier. */ else diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-59483.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-59483.C new file mode 100644 index 00000000000..b5b06d2c813 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-59483.C @@ -0,0 +1,31 @@ +// PR c++/59483 +// { dg-do compile { target c++11 } } + +struct X +{ +protected: + int i; +}; + +struct Y : X +{ + Y() + { + [&]{ X::i = 3; }(); + } +}; + +template +struct Y2 : T +{ + Y2() + { + [&]{ T::i = 3; }(); + } +}; + +int main() +{ + Y y; + Y2 y2; +} diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-61148.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-61148.C new file mode 100644 index 00000000000..879030caa0d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-61148.C @@ -0,0 +1,33 @@ +// PR c++/61148 +// { dg-do compile { target c++11 } } + +class DB +{ +protected: + void foo() {}; +}; + +class DC : public DB +{ +public: + DC() + { + [this]() {DB::foo();}(); + }; +}; + +template +class DC2 : public T +{ +public: + DC2() + { + [this]() {T::foo();}(); + }; +}; + +int main(void) +{ + DC x; + DC2 x2; +} -- 2.30.2