From 6b34716ba421d05190d66ab4660a48c0446f76c7 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Fri, 13 Jul 2018 15:33:27 +0000 Subject: [PATCH] [PR c++/86374] Name lookup failure in enclosing template https://gcc.gnu.org/ml/gcc-patches/2018-07/msg00701.html PR c++/86374 * pt.c (lookup_template_class_1): Use tsubst_aggr_type for contexts that are classes. * parser.c (cp_parser_template_id): Combine entering_scope decl & initializer. PR c++/86374 * g++.dg/pr86374.C: New. From-SVN: r262637 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/parser.c | 7 +++---- gcc/cp/pt.c | 11 +++++++++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/pr86374.C | 20 ++++++++++++++++++++ 5 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr86374.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a640259193c..1d5d66946f6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2018-07-13 Nathan Sidwell + + PR c++/86374 + * pt.c (lookup_template_class_1): Use tsubst_aggr_type for + contexts that are classes. + * parser.c (cp_parser_template_id): Combine entering_scope decl & + initializer. + 2018-07-12 Jakub Jelinek * decl2.c (cplus_decl_attributes): Don't diagnose vars without mappable diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 366a0d89460..d0f1e1e9701 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -15973,15 +15973,14 @@ cp_parser_template_id (cp_parser *parser, else if (DECL_TYPE_TEMPLATE_P (templ) || DECL_TEMPLATE_TEMPLATE_PARM_P (templ)) { - bool entering_scope; /* In "template ... A::", A is the abstract A template (rather than some instantiation thereof) only if is not nested within some other construct. For example, in "template void f(T) { A::", A is just an instantiation of A. */ - entering_scope = (template_parm_scope_p () - && cp_lexer_next_token_is (parser->lexer, - CPP_SCOPE)); + bool entering_scope + = (template_parm_scope_p () + && cp_lexer_next_token_is (parser->lexer, CPP_SCOPE)); template_id = finish_template_type (templ, arguments, entering_scope); } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index eae9e14d37d..9de9f500e2a 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -9368,8 +9368,15 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context, return found; } - context = tsubst (DECL_CONTEXT (gen_tmpl), arglist, - complain, in_decl); + context = DECL_CONTEXT (gen_tmpl); + if (context && TYPE_P (context)) + { + context = tsubst_aggr_type (context, arglist, complain, in_decl, true); + context = complete_type (context); + } + else + context = tsubst (context, arglist, complain, in_decl); + if (context == error_mark_node) return error_mark_node; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0c61e976f73..1780ca0074a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-07-13 Nathan Sidwell + + PR c++/86374 + * g++.dg/pr86374.C: New. + 2018-07-13 Qing Zhao PR middle-end/78809 diff --git a/gcc/testsuite/g++.dg/pr86374.C b/gcc/testsuite/g++.dg/pr86374.C new file mode 100644 index 00000000000..fd7115626e1 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr86374.C @@ -0,0 +1,20 @@ +// pr C++/86374 +// bogus lookup error +template +struct list { + static const int index = 1; + template struct addWithChecking {}; +}; + +template +struct find { + static const int result = 0; +}; + +template +template +struct list::addWithChecking +{ + static const int xres = + find >::result; // bogus error about index here. +}; -- 2.30.2