Commit d9338471 by Jason Merrill Committed by Jason Merrill

PR c++/85815 - reference to member of enclosing template.

	* search.c (lookup_base): Use currently_open_class.
	(lookup_member): Use it regardless of -fconcepts.
	* parser.c (cp_parser_postfix_dot_deref_expression): Check it.

From-SVN: r260782
parent 99dcfb5f
2018-05-25 Jason Merrill <jason@redhat.com> 2018-05-25 Jason Merrill <jason@redhat.com>
PR c++/85815 - reference to member of enclosing template.
* search.c (lookup_base): Use currently_open_class.
(lookup_member): Use it regardless of -fconcepts.
* parser.c (cp_parser_postfix_dot_deref_expression): Check it.
CWG 616, 1213 - value category of subobject references. CWG 616, 1213 - value category of subobject references.
* tree.c (lvalue_kind): Fix handling of ARRAY_REF of pointer. * tree.c (lvalue_kind): Fix handling of ARRAY_REF of pointer.
......
...@@ -7462,8 +7462,8 @@ pop_class_stack (void) ...@@ -7462,8 +7462,8 @@ pop_class_stack (void)
--current_class_stack[current_class_depth - 1].hidden; --current_class_stack[current_class_depth - 1].hidden;
} }
/* Returns 1 if the class type currently being defined is either T or /* If the class type currently being defined is either T or
a nested type of T. Returns the type from the current_class_stack, a nested type of T, returns the type from the current_class_stack,
which might be equivalent to but not equal to T in case of which might be equivalent to but not equal to T in case of
constrained partial specializations. */ constrained partial specializations. */
......
...@@ -7488,10 +7488,7 @@ cp_parser_postfix_dot_deref_expression (cp_parser *parser, ...@@ -7488,10 +7488,7 @@ cp_parser_postfix_dot_deref_expression (cp_parser *parser,
access (5.2.5) outside the member function body. */ access (5.2.5) outside the member function body. */
if (postfix_expression != current_class_ref if (postfix_expression != current_class_ref
&& scope != error_mark_node && scope != error_mark_node
&& !(processing_template_decl && !currently_open_class (scope))
&& current_class_type
&& (same_type_ignoring_top_level_qualifiers_p
(scope, current_class_type))))
{ {
scope = complete_type (scope); scope = complete_type (scope);
if (!COMPLETE_TYPE_P (scope) if (!COMPLETE_TYPE_P (scope)
...@@ -192,6 +192,9 @@ lookup_base (tree t, tree base, base_access access, ...@@ -192,6 +192,9 @@ lookup_base (tree t, tree base, base_access access,
else else
{ {
t = complete_type (TYPE_MAIN_VARIANT (t)); t = complete_type (TYPE_MAIN_VARIANT (t));
if (dependent_type_p (t))
if (tree open = currently_open_class (t))
t = open;
t_binfo = TYPE_BINFO (t); t_binfo = TYPE_BINFO (t);
} }
...@@ -1117,7 +1120,7 @@ lookup_member (tree xbasetype, tree name, int protect, bool want_type, ...@@ -1117,7 +1120,7 @@ lookup_member (tree xbasetype, tree name, int protect, bool want_type,
/* Make sure we're looking for a member of the current instantiation in the /* Make sure we're looking for a member of the current instantiation in the
right partial specialization. */ right partial specialization. */
if (flag_concepts && dependent_type_p (type)) if (dependent_type_p (type))
if (tree t = currently_open_class (type)) if (tree t = currently_open_class (type))
type = t; type = t;
......
// PR c++/85815
// { dg-do compile { target c++11 } }
template<class T>
class A {
static A* INSTANCE;
void foobar();
void moo() {}
};
template<class T>
A<T>* A<T>::INSTANCE = nullptr;
template<class T>
void A<T>::foobar() {
auto x = []() {
INSTANCE->moo();
};
}
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