From: Jason Merrill Date: Fri, 25 May 2018 21:03:07 +0000 (-0400) Subject: PR c++/85815 - reference to member of enclosing template. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d9338471b91bbe6e1579088c7d40ab257ac3764d;p=gcc.git 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9c2548d5377..58fc696c571 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2018-05-25 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. + CWG 616, 1213 - value category of subobject references. * tree.c (lvalue_kind): Fix handling of ARRAY_REF of pointer. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index a17c8ed8b45..ab68b9be42a 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -7462,8 +7462,8 @@ pop_class_stack (void) --current_class_stack[current_class_depth - 1].hidden; } -/* Returns 1 if the class type currently being defined is either T or - a nested type of T. Returns the type from the current_class_stack, +/* If the class type currently being defined is either T or + 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 constrained partial specializations. */ diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index f5a6d940601..d17beb8f930 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -7488,10 +7488,7 @@ cp_parser_postfix_dot_deref_expression (cp_parser *parser, access (5.2.5) outside the member function body. */ if (postfix_expression != current_class_ref && scope != error_mark_node - && !(processing_template_decl - && current_class_type - && (same_type_ignoring_top_level_qualifiers_p - (scope, current_class_type)))) + && !currently_open_class (scope)) { scope = complete_type (scope); if (!COMPLETE_TYPE_P (scope) diff --git a/gcc/cp/search.c b/gcc/cp/search.c index e343a15c042..c2860b0dc9a 100644 --- a/gcc/cp/search.c +++ b/gcc/cp/search.c @@ -192,6 +192,9 @@ lookup_base (tree t, tree base, base_access access, else { 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); } @@ -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 right partial specialization. */ - if (flag_concepts && dependent_type_p (type)) + if (dependent_type_p (type)) if (tree t = currently_open_class (type)) type = t; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-dependent1.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-dependent1.C new file mode 100644 index 00000000000..6fd2bb379bf --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-dependent1.C @@ -0,0 +1,19 @@ +// PR c++/85815 +// { dg-do compile { target c++11 } } + +template +class A { + static A* INSTANCE; + void foobar(); + void moo() {} +}; + +template +A* A::INSTANCE = nullptr; + +template +void A::foobar() { + auto x = []() { + INSTANCE->moo(); + }; +}