From patchwork Fri Jul 13 15:32:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 943654 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-481504-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="K4DcV2uu"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41RxdF0KG5z9s2x for ; Sat, 14 Jul 2018 01:32:31 +1000 (AEST) Received: (qmail 117049 invoked by alias); 13 Jul 2018 15:32:24 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 116947 invoked by uid 89); 13 Jul 2018 15:32:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=UD:pt.c, pt.c, ptc, thereof X-HELO: mail-yb0-f177.google.com Received: from mail-yb0-f177.google.com (HELO mail-yb0-f177.google.com) (209.85.213.177) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 13 Jul 2018 15:32:22 +0000 Received: by mail-yb0-f177.google.com with SMTP id c10-v6so11152280ybf.9 for ; Fri, 13 Jul 2018 08:32:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:cc:from:subject:message-id:date:user-agent:mime-version :content-language; bh=HNEGMSGQ8ozdVJdoZXykHO9+GUdOcNHEb4Y9yklGZB8=; b=K4DcV2uuaYnHejdslSLYDor6e809g9qoemeStExxhHjo5PhzFscrp/utOFRaf8KJ+a PnwSORVBz8XaqmWFHoOOy1JezC6kDyLzdtVI6Y1jWJ6QMpapmtQK5Z9mnmmtf127+8XK QVtGa+yJK9zSY0D4aQu03QlZxP/wMpTVW640JbgM8wODm/7N8BKYJsdkpxoFjzQCL34C wXFQG2GyjA1q4B1P2PS2XZGRkPIoQeutnevpt4/cI3wBEWCrjv4hTone405BcgBgpzbN n+THFomDq2MASYRODL2/8JnyFg2jzYgEhRJybIded6fwCOyHqw5+6ABwbCGPuNUxXpA4 TWCA== Received: from ?IPv6:2620:10d:c0a1:1102:495f:7267:5ff:a250? ([2620:10d:c091:180::1:2fb6]) by smtp.googlemail.com with ESMTPSA id l2-v6sm7818794ywl.41.2018.07.13.08.32.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 08:32:19 -0700 (PDT) Sender: Nathan Sidwell To: GCC Patches Cc: Jason Merrill From: Nathan Sidwell Subject: [PR c++/86374] Name lookup failure in enclosing template Message-ID: <5e721933-1bfe-7911-7b86-856ed0a9bc9b@acm.org> Date: Fri, 13 Jul 2018 11:32:17 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 This was a latent problem exposed by Jason's fix for 85815. There we needed to find the class in the scope stack. Unfortunately, here we'd pushed an (incomplete) instantiation list, rather than the general template list. We were previously getting away with that because we'd do the lookup in the a tsubstd scope, that had found the general template in another way. The fix is to have lookup_template call tsubst_aggr_class directly for contexts that are classes, with the entering_scope flag set. That way we figure that list is the general template. This matches the code in tsubst_aggr_class itself, when it's tsubsting the context of the class it is dealing with. A small drive-by cleanup in the parser. Committing to trunk now. will commit to gcc-8 after testing there. nathan 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. PR c++/86374 * g++.dg/pr86374.C: New. Index: cp/parser.c =================================================================== --- cp/parser.c (revision 262582) +++ cp/parser.c (working copy) @@ -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); } Index: cp/pt.c =================================================================== --- cp/pt.c (revision 262582) +++ cp/pt.c (working copy) @@ -9368,8 +9368,15 @@ lookup_template_class_1 (tree d1, tree a 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; Index: testsuite/g++.dg/pr86374.C =================================================================== --- testsuite/g++.dg/pr86374.C (revision 0) +++ testsuite/g++.dg/pr86374.C (working copy) @@ -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. +};