From patchwork Wed Mar 28 12:25:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 892116 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-475554-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="nWV7PI3P"; 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 40B6YY5dCQz9ryk for ; Wed, 28 Mar 2018 23:26: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=ORZ2GmFehQZaAOFhceQP7sU/iwIZvrPFs7MYgMwLOdMjzkZBGe RFEi/D3F1j/dxlcvMscCP6RFONV6ecUU0h2LJga38Y7QCoffjd5y+9VVf19fw+fi BMmZXJ6Vga9dybuaRZF4pIjxOghhaDjHnWTlP1vMDM2k3boSdx0UXJ6L8= 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=8av6WGD9HZRHAVL6e0eKL5byLyg=; b=nWV7PI3PCpMjG6JkUa9q 27rzgrTZcgyr+r8izWh1EgDawZDLgfUW5hoPc8/7d80u7RjuGP+I2fgSeUMSlrxn fnc6UycC0tqMZH3mBpWW6zzArpMmvQMU0MWKu3DTPohdFzotMLsZfJpnjvGxf4z+ i4K7DqyEKLtKHub8CevZ6OM= Received: (qmail 11322 invoked by alias); 28 Mar 2018 12:26: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 11243 invoked by uid 89); 28 Mar 2018 12:26: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, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Early X-HELO: aserp2120.oracle.com Received: from aserp2120.oracle.com (HELO aserp2120.oracle.com) (141.146.126.78) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 28 Mar 2018 12:25:58 +0000 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w2SCIKAH069240; Wed, 28 Mar 2018 12:25:57 GMT Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2h0ax8g11n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Mar 2018 12:25:57 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w2SCPtND022763 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Mar 2018 12:25:56 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w2SCPto8002614; Wed, 28 Mar 2018 12:25:55 GMT Received: from [192.168.1.4] (/80.181.236.138) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 28 Mar 2018 05:25:54 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] PR 85028 ("[8 Regression] ICE on invalid C++ code: in tsubst_default_argument, at cp/pt.c:12340") Message-ID: <5c61f1e5-5695-54d3-91e4-72f71cf39667@oracle.com> Date: Wed, 28 Mar 2018 14:25:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8845 signatures=668695 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-1803280132 X-IsSubscribed: yes Hi, as I said in the audit trail, in its way this error recovery issue is somewhat interesting: Jason's r251422 added some code at the beginning of tsubst_default_argument, included the gcc_assert that triggers here. In fact, parmtype is only used in the assertion thus the error recovery check could be moved inside the assertion, something like (appears to also pass testing, lightly tested, so far): gcc_assert (parmtype == error_mark_node || same_type_ignoring_top_level_qualifiers_p (type, parmtype)); and for this bug we would be back to the gcc-7 status, thus we would not ICE and we would issue *2* errors, one for the parameter and then one more for the default argument itself, at instantiation time. In fact, some other compilers also do that. Or, as I have below, we can return early, after the first error. Tested x86_64-linux. Thanks, Paolo. /////////////////// /cp 2018-03-28 Paolo Carlini PR c++/85028 * pt.c (tsubst_default_argument): Early return if the type of the parameter is erroneous. /testsuite 2018-03-28 Paolo Carlini PR c++/85028 * g++.dg/other/default13.C: New. Index: cp/pt.c =================================================================== --- cp/pt.c (revision 258915) +++ cp/pt.c (working copy) @@ -12337,6 +12337,9 @@ tsubst_default_argument (tree fn, int parmnum, tre tree parmtype = TREE_TYPE (parm); if (DECL_BY_REFERENCE (parm)) parmtype = TREE_TYPE (parmtype); + if (parmtype == error_mark_node) + return error_mark_node; + gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, parmtype)); tree *slot; Index: testsuite/g++.dg/other/default13.C =================================================================== --- testsuite/g++.dg/other/default13.C (nonexistent) +++ testsuite/g++.dg/other/default13.C (working copy) @@ -0,0 +1,11 @@ +// PR c++/85028 + +struct A; + +template < typename > struct B +{ + B (int, A = A()) : f (0) {} // { dg-error "incomplete type" } + int f; +}; + +B < int > b (0);