From patchwork Fri Feb 16 22:30:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 874681 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-473471-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="PKuO7bgK"; 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 3zjnt459NMz9sP9 for ; Sat, 17 Feb 2018 09:31:07 +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:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=CK+Rl2VB0LqLBwX4rC9TCGtIWgX9iB0nThIAy9/LjvFlccQOHp qIq0YmT3epDAWZzt8WSV7LJIyNGs0PMNV2KiKSXdL20Xof+wGDVSlW2l4cGY3c23 ZLuunoVTvH3wpmbo3b02ZFPCJlq7BoaML8wntahptJtWFYTyAS+KoAOX4= 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:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=EbxWtX6FjZH7r+cCR9W0qkSx+gU=; b=PKuO7bgKk7ia2CFTUP5E huOlGrQGWr1OmOeWDPYnuQWDIRC2ock6gzkLCPGCPMy22MpICQuvr9/MNYUHhCmT MqXDChtXViWftAKJngALh24M9jcGn/WZJqXzeFVJa+7GjwyrhBdz0vqjz8v7jwg7 HZ1t9dmE/IoN9l1+zs/TK7c= Received: (qmail 75682 invoked by alias); 16 Feb 2018 22:31:00 -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 75657 invoked by uid 89); 16 Feb 2018 22:31:00 -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, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: userp2130.oracle.com Received: from userp2130.oracle.com (HELO userp2130.oracle.com) (156.151.31.86) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Feb 2018 22:30:58 +0000 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w1GMRCAM015497; Fri, 16 Feb 2018 22:30:55 GMT Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2g65550ngb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Feb 2018 22:30:55 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w1GMUsWf006364 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 16 Feb 2018 22:30:54 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w1GMUst0000709; Fri, 16 Feb 2018 22:30:54 GMT Received: from [192.168.1.4] (/79.52.198.133) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 16 Feb 2018 14:30:53 -0800 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch/RFC] PR 84348 ("[7/8 Regression] ICE with invalid friend declaration") Message-ID: Date: Fri, 16 Feb 2018 23:30:50 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8807 signatures=668673 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1802160257 X-IsSubscribed: yes Hi, here we ICE during error recovery when, after emitting a correct error from grokdeclarator, we go on, we only clear friendp, and grokfield proceeds to call cp_finish_decl where 'gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (auto_node));' triggers. We could imagine solving the problem in various ways... If we want to do something as early as possible, in grokdeclarator, over the years in turn we handled different cases in different ways related to the error recovery effects, mostly. A straightforward solution, which I'm finishing testing, would be just bailing-out after the error, alternately we could also imagine something relatively sophisticated like going on, but also setting type = error_mark_node conditional to type_uses_auto (auto) thus mimicking the error recovery strategy we use above for a non-friend ill-formed variant. Just unconditionally setting type = error_mark_node doesn't seem morally correct to me - even if probably it would also pass the testsuite - because what we are actually diagnosing to the user, in fact the first problem in such snippet in parsing order, doesn't have to do with the type per se, but with friend - the diagnostic for 'friend int foo' is the same. As usual I'm on x86_64-linux. Thanks, Paolo. //////////////////// Index: cp/decl.c =================================================================== --- cp/decl.c (revision 257767) +++ cp/decl.c (working copy) @@ -12141,7 +12141,7 @@ grokdeclarator (const cp_declarator *declarator, { error ("%qE is neither function nor member function; " "cannot be declared friend", unqualified_id); - friendp = 0; + return error_mark_node; } decl = NULL_TREE; } Index: testsuite/g++.dg/cpp0x/auto50.C =================================================================== --- testsuite/g++.dg/cpp0x/auto50.C (nonexistent) +++ testsuite/g++.dg/cpp0x/auto50.C (working copy) @@ -0,0 +1,7 @@ +// PR c++/84348 +// { dg-do compile { target c++11 } } + +template struct A +{ + friend auto foo; // { dg-error "cannot be declared friend" } +}; Index: testsuite/g++.dg/parse/friend12.C =================================================================== --- testsuite/g++.dg/parse/friend12.C (revision 257767) +++ testsuite/g++.dg/parse/friend12.C (working copy) @@ -3,5 +3,4 @@ struct A { friend int i = 0; // { dg-error "cannot be declared friend" } -// { dg-error "non-static data member" "" { target { ! c++11 } } .-1 } };