From patchwork Fri Feb 16 14:28:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 874449 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-473419-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="uQII/ROQ"; 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 3zjb9937k0z9sNr for ; Sat, 17 Feb 2018 01:28:28 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=oN+HWQUrUMZEt/pgYPfYzrbnQBdJUNdm+6LMSdWdyKrLgTv179 w7gDhl6MGEOzA4VvpLlCQ9blr2GGCSe5CepL+iAEizNkEu8qlYBxbzE4cNsxWPbj 7BCN/uDbN+B5xQzpvbmXrOB+zFy3EVjTP5Qfx4dirNQTrouOGq0hFL3S4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=etLalp328Qv8iV7cuW2l917eJn8=; b=uQII/ROQYqYOCc+KtK7w gmm5FOWGP6Zb1QyRxLN/KS8MTYwwX8eYm+QAlCdc0yysOGkf0HYaY/ZUvOiWTQcC Ks1Ha/S9n44Y1Tm47ZOGoqiYm8gKy1L7fPMbHkS1zBZvwjbuAu5AGmB40l6Cr7V/ Det4i1+qPZ7WfxLKjfNjjvE= Received: (qmail 34545 invoked by alias); 16 Feb 2018 14:28:21 -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 34535 invoked by uid 89); 16 Feb 2018 14:28:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=friend X-HELO: mail-yw0-f176.google.com Received: from mail-yw0-f176.google.com (HELO mail-yw0-f176.google.com) (209.85.161.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Feb 2018 14:28:19 +0000 Received: by mail-yw0-f176.google.com with SMTP id b16so1561836ywh.12 for ; Fri, 16 Feb 2018 06:28:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=43Uy3reW/9jdBTfkScNv92h1swPWBNIQ4aHwuZvT8QY=; b=oGkWKDltCSgzlLX+0Gd9Rc6Csep184Zeg5WbJT1TtWYgX/A0+uNqprevMG5To0kubS cqZ//pdNH1oJT/quXnm4aXqnC7Hwe402GRXmVy4H9xJr71puUlHWajWYc/Q4pKpJzph0 LwlHhafHfN++xJ6RM2/SYHFxUo0zvA0efLPzrT6VWn7u/p9TWwObciiFmkeKbJ3DZhbJ fry8mmMAMMlu7nJ1gjo992XuoG7McJ2E1wil5UjFwovp5cBc5SQgEzvF1dLTUbV9YjCZ DA0HRDDpScjEUG8TXYOn/Apm3lTYts2ylCyK4T6S5TG/UCmbebDTC1gTzCDDMsT4+koX kuxg== X-Gm-Message-State: APf1xPAdwEV5/z3Jnu7pmYhR4oNtrrC0ufwdlNS16KwDO1s9DUWcj3K1 sZ/BcZT7pib8tMHAOqEsmkI= X-Google-Smtp-Source: AH8x224Lmloc99EIXiWEJDrcxXSJ0vV76nTuo633mNodeKZZ4YDvePLs1UaRtnjlIB6gnWkPGcuqTw== X-Received: by 10.129.124.70 with SMTP id x67mr4807287ywc.314.1518791297252; Fri, 16 Feb 2018 06:28:17 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::3:a8f3]) by smtp.googlemail.com with ESMTPSA id g1sm6845967ywh.32.2018.02.16.06.28.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Feb 2018 06:28:16 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: {PR c++/84375] Fix ICE after bad friend Message-ID: <9e6c9b16-3541-e6d7-4a7a-d088d12ed60f@acm.org> Date: Fri, 16 Feb 2018 09:28:15 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 This fixes an ICE after attempted friend declaration in a local class. We were going onto push it into the local binding, but that's a binding in the class being defined, because . Just bail out immediately. nathan 2018-02-16 Nathan Sidwell PR c++/84375 * name-lookup.c (do_pushdecl): Bail out on bad local friend injection. * g++.dg/lookup/pr84375.C: New. Index: gcc/cp/name-lookup.c =================================================================== --- gcc/cp/name-lookup.c (revision 257733) +++ gcc/cp/name-lookup.c (working copy) @@ -3079,12 +3079,16 @@ do_pushdecl (tree decl, bool is_friend) if (is_friend) { if (level->kind != sk_namespace) - /* In a local class, a friend function declaration must - find a matching decl in the innermost non-class scope. - [class.friend/11] */ - error ("friend declaration %qD in local class without " - "prior local declaration", decl); - else if (!flag_friend_injection) + { + /* In a local class, a friend function declaration must + find a matching decl in the innermost non-class scope. + [class.friend/11] */ + error ("friend declaration %qD in local class without " + "prior local declaration", decl); + /* Don't attempt to push it. */ + return error_mark_node; + } + if (!flag_friend_injection) /* Hide it from ordinary lookup. */ DECL_ANTICIPATED (decl) = DECL_HIDDEN_FRIEND_P (decl) = true; } Index: gcc/testsuite/g++.dg/lookup/pr84375.C =================================================================== --- gcc/testsuite/g++.dg/lookup/pr84375.C (revision 0) +++ gcc/testsuite/g++.dg/lookup/pr84375.C (working copy) @@ -0,0 +1,9 @@ +// PR c++/84375 ICE after error + +void foo() +{ + struct A + { + friend void A(); // { dg-error "local class without prior local" } + }; +}