From patchwork Fri Jul 14 17:32:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 788670 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3x8KWQ1hBGz9s7m for ; Sat, 15 Jul 2017 03:32:17 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="EugUdDsE"; dkim-atps=neutral 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=eTYxA1aOLaTIbQ+QVvYiLomX3rQTedZY5sBsH0IQOunHsYbjcE a50JX8Dj1gtMDZc/6z7TFPeATF+4FHIwF4ZCGIInGYStLMS1MK0QgZPoYcMg+b4q zQzCcz/GIIzoHRenSYbj7w0IaqNLl30bQrNmt5T2r+kvt1MEMmZDwyazA= 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=6k47kAGwUa7cWSgLS92RoFgm9WY=; b=EugUdDsEPVufIhXRD0Xk TkqAssDStEr/VMPK1ZY0zxSs8dZ4Tn7+ZVc9j5TsPc64dcfexs+FISC24cTsjqxj iBodisniUbPt8NrGPboSy+jBMIWtvf5qHZ3ZIWhn9eDSElpfCjapxzsDs5DnbK6P P1sDVKE0c5rxVC57kuZMxYc= Received: (qmail 125336 invoked by alias); 14 Jul 2017 17:32:09 -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 125320 invoked by uid 89); 14 Jul 2017 17:32:08 -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, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=viable X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 14 Jul 2017 17:32:07 +0000 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v6EHW4l0014374 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 Jul 2017 17:32:05 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v6EHW4JG011942 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 Jul 2017 17:32:04 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v6EHW33e014880; Fri, 14 Jul 2017 17:32:03 GMT Received: from [192.168.1.4] (/87.10.227.24) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 14 Jul 2017 10:32:03 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] PR 79790 ("[C++17] ICE class template argument deduction") Message-ID: <25e893cd-0bf5-4c5e-24b7-70daba6793dc@oracle.com> Date: Fri, 14 Jul 2017 19:32:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, in this C++17 ICE on invalid we crash when, in do_class_deduction, build_new_function_call is called with a null first argument. What is happening is pretty simple to analyze: for the broken snippet, there are no cands and elided is false, because the issue isn't that candidates are elided because explicit, instead that there are no viable candidates whatsoever, because args->length () == 3 and we don't even have the implicit deduction guides. Alternately to the straightforward fix I'm proposing below, a literal reading of the standard [16.3.1.8] suggests that we could also consider generating the implicit deduction guides even when args->length () >= 2 and the copy deduction guide even when args->length () != 1, that is unconditionally. While working on the bug I also noticed that we can simplify a bit the code generating the implicit deduction guides: if I'm not mistaken, when we pass types as first argument of build_deduction_guide - for implicit guides, that is - the deduction guide is never explicit. thus DECL_NONCONVERTING_P is never true. It's an unrelated tweak, anyway, which we can consider applying by itself if we don't change the code generating the implicit deduction guides. Thanks! Paolo. /////////////////////// /cp 2017-07-14 Paolo Carlini PR c++/79790 * pt.c (do_class_deduction): Handle the case of no viable implicit deduction guides; simplify the code generating implicit deduction guides. /testsuite 2017-07-14 Paolo Carlini PR c++/79790 * g++.dg/cpp1z/class-deduction42.C: New. Index: cp/pt.c =================================================================== --- cp/pt.c (revision 250186) +++ cp/pt.c (working copy) @@ -25439,11 +25439,7 @@ do_class_deduction (tree ptype, tree tmpl, tree in if (gtype) { tree guide = build_deduction_guide (gtype, outer_args, complain); - if ((flags & LOOKUP_ONLYCONVERTING) - && DECL_NONCONVERTING_P (STRIP_TEMPLATE (guide))) - elided = true; - else - cands = lookup_add (guide, cands); + cands = lookup_add (guide, cands); } } @@ -25454,6 +25450,12 @@ do_class_deduction (tree ptype, tree tmpl, tree in "user-declared constructors", type); return error_mark_node; } + else if (!cands && call == error_mark_node) + { + error ("cannot deduce template arguments for copy-initialization" + " of %qT, as it has no viable implicit deduction guides", type); + return error_mark_node; + } if (call == error_mark_node) { Index: testsuite/g++.dg/cpp1z/class-deduction42.C =================================================================== --- testsuite/g++.dg/cpp1z/class-deduction42.C (revision 0) +++ testsuite/g++.dg/cpp1z/class-deduction42.C (working copy) @@ -0,0 +1,10 @@ +// PR c++/79790 +// { dg-options -std=c++1z } + +template +struct array +{ + int a [N]; +}; + +array a = { 1, 2, 3 }; // { dg-error "cannot deduce" }