From patchwork Tue Apr 3 09:02:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 894475 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-475723-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="a9qj0SH3"; 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 40FjmB3sCJz9ryr for ; Tue, 3 Apr 2018 19:02:48 +1000 (AEST) 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=ea3F4dPsmsNQSAhf3aPyCkM/ogtizC6J3V8VUfweg84yHBkIdQ EDAnTCTdNF8mLRx60qeWD77MSs+BjCL0pkwKRbRlTeFKNb5tzI+E5NWJZuPPJt+5 8CONPdkkKcVxmfbtKRVtyq+c512FmGvGclXoT/UGtsBc7AHcANBEvcGfA= 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=6k4Z45G4EkhuASoyOED7L7Ibdt8=; b=a9qj0SH33gtjVnoTI0eG PyNYaaVR1+WUcaReTTmKFOxYBJOOBukZRESggcmdDkuRxmz9Llymxr9/FHIzhhOK o5jSbC1K3H3hMrs99jznH19FO1x/0D90Bb/8KckxTTpRWokXW224JDdr5EjfjWEw /+36/C+gJ1Kgsz6Ixs7plrE= Received: (qmail 26548 invoked by alias); 3 Apr 2018 09:02:40 -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 25802 invoked by uid 89); 3 Apr 2018 09:02:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-16.1 required=5.0 tests=BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=surprisingly, H*RU:192.168.1.4, H*r:ip*192.168.1.4, Hx-spam-relays-external:192.168.1.4 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; Tue, 03 Apr 2018 09:02:32 +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 w33923c1022646; Tue, 3 Apr 2018 09:02:30 GMT Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2h46cyr4ta-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Apr 2018 09:02:29 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w3392SmI027315 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 3 Apr 2018 09:02:29 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w3392RFj002201; Tue, 3 Apr 2018 09:02:27 GMT Received: from [192.168.1.4] (/79.53.236.120) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 03 Apr 2018 02:02:27 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] ("[7/8 Regression] ICE with failed class template argument deduction because of invalid template parameter") Message-ID: <05885dfd-8195-0d61-e1ff-156b2631712a@oracle.com> Date: Tue, 3 Apr 2018 11:02:23 +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=8851 signatures=668697 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-1804030088 X-IsSubscribed: yes Hi, the reason why we ICE here is very simple: we pass an error_mark_node generated in cp_parser_template_parameter_list to rewrite_template_parm which ICEs (via get_template_parm_index). I believe it makes sense to robustify the latter like all the other functions involved in build_deduction_guide. The next, error recovery quality, issue is whether or not we still want to produce diagnostic about class template argument deduction failing: today I noticed - somewhat surprisingly - that some compilers still do that (however the diagnostic is more terse: eg, one additional error and two notes, not two errors and five notes!). I had tested the below which suppresses those additional errors by returning error_mark_node from build_deduction_guide if one of those parsing-time error_mark_nodes is encountered in the build_deduction_guide loop - and lays out a bit of infrastructure. Tested x86_64-linux. Thanks, Paolo. //////////////// /cp 2018-04-03 Paolo Carlini PR c++/84768 * pt.c (rewrite_template_parm): If the first argument is error_mark_node return it immediately. (build_deduction_guide): Check the return value of the latter for error_mark_node. (do_class_deduction): Check the return value of the latter. /testsuite 2018-04-03 Paolo Carlini PR c++/84768 * g++.dg/cpp1z/class-deduction52.C: New. Index: cp/pt.c =================================================================== --- cp/pt.c (revision 258972) +++ cp/pt.c (working copy) @@ -25800,6 +25800,9 @@ static tree rewrite_template_parm (tree olddecl, unsigned index, unsigned level, tree tsubst_args, tsubst_flags_t complain) { + if (olddecl == error_mark_node) + return error_mark_node; + tree oldidx = get_template_parm_index (olddecl); tree newtype; @@ -25935,6 +25938,7 @@ build_deduction_guide (tree ctor, tree outer_args, else { ++processing_template_decl; + bool ok = true; fn_tmpl = (TREE_CODE (ctor) == TEMPLATE_DECL ? ctor @@ -26005,6 +26009,8 @@ build_deduction_guide (tree ctor, tree outer_args, tree olddecl = TREE_VALUE (oldelt); tree newdecl = rewrite_template_parm (olddecl, index, level, tsubst_args, complain); + if (newdecl == error_mark_node) + ok = false; tree newdef = tsubst_template_arg (TREE_PURPOSE (oldelt), tsubst_args, complain, ctor); tree list = build_tree_list (newdef, newdecl); @@ -26026,7 +26032,10 @@ build_deduction_guide (tree ctor, tree outer_args, current_template_parms = save_parms; } + --processing_template_decl; + if (!ok) + return error_mark_node; } if (!memtmpl) @@ -26153,6 +26162,8 @@ do_class_deduction (tree ptype, tree tmpl, tree in for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (type)); iter; ++iter) { tree guide = build_deduction_guide (*iter, outer_args, complain); + if (guide == error_mark_node) + return error_mark_node; if ((flags & LOOKUP_ONLYCONVERTING) && DECL_NONCONVERTING_P (STRIP_TEMPLATE (guide))) elided = true; @@ -26204,6 +26215,8 @@ do_class_deduction (tree ptype, tree tmpl, tree in if (gtype) { tree guide = build_deduction_guide (gtype, outer_args, complain); + if (guide == error_mark_node) + return error_mark_node; cands = lookup_add (guide, cands); } } Index: testsuite/g++.dg/cpp1z/class-deduction52.C =================================================================== --- testsuite/g++.dg/cpp1z/class-deduction52.C (nonexistent) +++ testsuite/g++.dg/cpp1z/class-deduction52.C (working copy) @@ -0,0 +1,11 @@ +// PR c++/84768 +// { dg-additional-options -std=c++17 } + +template struct A {}; + +template struct B +{ + template B(A); // { dg-error "declared" } +}; + +B b = A();