Commit adb50dfb by Ville Voutilainen Committed by Jason Merrill

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
parent 9b2b7279
2014-06-02 Ville Voutilainen <ville.voutilainen@gmail.com>
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 <amacleod@redhat.com> 2014-06-02 Andrew MacLeod <amacleod@redhat.com>
* decl.c: Include builtins.h. * decl.c: Include builtins.h.
......
...@@ -917,9 +917,11 @@ accessible_p (tree type, tree decl, bool consider_local_p) ...@@ -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 /* Figure out where the reference is occurring. Check to see if
DECL is private or protected in this scope, since that will DECL is private or protected in this scope, since that will
determine whether protected access is allowed. */ determine whether protected access is allowed. */
if (current_class_type) tree ct = current_nonlambda_class_type ();
if (ct)
protected_ok = protected_accessible_p (decl, protected_ok = protected_accessible_p (decl,
current_class_type, binfo); ct,
binfo);
/* Now, loop through the classes of which we are a friend. */ /* Now, loop through the classes of which we are a friend. */
if (!protected_ok) if (!protected_ok)
......
...@@ -1836,10 +1836,11 @@ check_accessibility_of_qualified_id (tree decl, ...@@ -1836,10 +1836,11 @@ check_accessibility_of_qualified_id (tree decl,
/* If the reference is to a non-static member of the /* If the reference is to a non-static member of the
current class, treat it as if it were referenced through current class, treat it as if it were referenced through
`this'. */ `this'. */
tree ct;
if (DECL_NONSTATIC_MEMBER_P (decl) if (DECL_NONSTATIC_MEMBER_P (decl)
&& current_class_ptr && current_class_ptr
&& DERIVED_FROM_P (scope, current_class_type)) && DERIVED_FROM_P (scope, ct = current_nonlambda_class_type ()))
qualifying_type = current_class_type; qualifying_type = ct;
/* Otherwise, use the type indicated by the /* Otherwise, use the type indicated by the
nested-name-specifier. */ nested-name-specifier. */
else else
......
// PR c++/59483
// { dg-do compile { target c++11 } }
struct X
{
protected:
int i;
};
struct Y : X
{
Y()
{
[&]{ X::i = 3; }();
}
};
template <class T>
struct Y2 : T
{
Y2()
{
[&]{ T::i = 3; }();
}
};
int main()
{
Y y;
Y2<X> y2;
}
// 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 T>
class DC2 : public T
{
public:
DC2()
{
[this]() {T::foo();}();
};
};
int main(void)
{
DC x;
DC2<DB> x2;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment