From patchwork Wed Dec 14 14:05:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 88029 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp211082qgi; Wed, 14 Dec 2016 06:05:40 -0800 (PST) X-Received: by 10.99.241.21 with SMTP id f21mr187375919pgi.110.1481724340617; Wed, 14 Dec 2016 06:05:40 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 2si53073322pft.109.2016.12.14.06.05.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Dec 2016 06:05:40 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-444405-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-444405-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-444405-patch=linaro.org@gcc.gnu.org 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=UFXat+QopCS4WMsrcgDY8JeARUzLv++khvTkkPjrxHZcYNzMyZ f8YG/7tnSLIeJJfVviSsIJ5qcTScgm/hab5VEI9yZRYzjf1Ft3n5IKO12ksWxXeB 782FjK9P5lPxvRYXJDaNeuOpMu3JNJCEVyAtRVdM9BTx+ONjWEyrqRD+k= 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=2h/vdg8awjYtpVdm4g53IObU4MM=; b=kY2uFYns8k3onSMbwFxy D18eNc+V14mwYKXWNCZWFMPl7inx3rpQxVZnmqXK+eObPYHe4uoAo9EY6yMvMOJa GiPyghL9cW10PmpDaURFqerDSFjsnhTmLjfOc10yEYk4fqEYHrHlTdeCyb2vpDEn 0Nnnxben/qAV/OgxW3mS+7U= Received: (qmail 58949 invoked by alias); 14 Dec 2016 14:05:28 -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 58928 invoked by uid 89); 14 Dec 2016 14:05:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=error_mark_node, tparms, deduction, tsubst X-HELO: mail-yb0-f193.google.com Received: from mail-yb0-f193.google.com (HELO mail-yb0-f193.google.com) (209.85.213.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 14 Dec 2016 14:05:17 +0000 Received: by mail-yb0-f193.google.com with SMTP id d59so1944476ybi.2 for ; Wed, 14 Dec 2016 06:05:17 -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:cc:from:subject:message-id:date :user-agent:mime-version; bh=KjH9ZVM0hMibi+ZDRNbOCSec7oCUF8wnnQ4YzweCevw=; b=D44Xkb0ebAQY01SBVy7zBsU5pVUHFtn+jwVqUianpyykyV4AY+aQ5AStfeIrwBI4V3 lwajUvSn4MN+e8qCTBdUbIC9yWF/WkYe++nz+aYgrRnfsM0bV0+5Kvn1WgPoOyrCyWOJ YwesAxWryiVTaYcUtO4sb8C+SQ3DmEpHlaiALZQEl0+DIwEZaHMwapGOdTkE2O3YDlmt eziWuV+UeXE1QTuysh23fe7Z1Tq9b34Ed2Vrl0sZV0Fgi/Nxqeyj+U+ydFfyBFrE2r7U s6vSq4KWM1IHvltWtVo5lOKvDCMCEV0MzcDeBbqH6Lb95ua5qZj7pdL2D8dAwLmDwhsk QLXQ== X-Gm-Message-State: AKaTC00rmf2ikje79gy9cHOPlu7HYk4nUTuz9LZVfyTeN3HAV/qycPqD81peVV9TTBltBA== X-Received: by 10.13.214.210 with SMTP id y201mr110609761ywd.254.1481724315840; Wed, 14 Dec 2016 06:05:15 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::640]) by smtp.googlemail.com with ESMTPSA id g133sm21342338ywe.1.2016.12.14.06.05.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Dec 2016 06:05:15 -0800 (PST) To: Jason Merrill Cc: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] c++/78701 ICE in default arg unification Message-ID: Date: Wed, 14 Dec 2016 09:05:14 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 This patch fixes 78701. The problematic case with a non-type template arg whose default value is dependent on a previous non-type arg that failed to be deduced on the first iteration of the loop in type_unification_real. Just before the tsubst_template_arg we've already done: if (TREE_CODE (parm) == PARM_DECL && uses_template_parms (TREE_TYPE (parm)) && saw_undeduced < 2) continue; to check the type of the arg is deduced. This patch adds the equivalent check just after tsubsting, to see if we managed to get all the template parms replaced. I wasn't sure if it should check for PARM_DECL, perhaps convert_template_argument can cope with the case of a non-subst template parm, so checking would save a call to uses_template_parms in the type-parm case? Unfortunately because at this point we've pushed some state, we can't simply 'continue'. Hence I chose to set arg to NULL and check it later. The deleted continue is the last statement of the loop, hence deleted. ok? nathan -- Nathan Sidwell 2016-12-14 Nathan Sidwell PR c++/78701 * pt.c (type_unification_real): Check tsubst arg doesn't have remaining template parms before converting it. PR c++/78701 * g++.dg/cpp0x/pr78701.C: New. Index: cp/pt.c =================================================================== --- cp/pt.c (revision 243580) +++ cp/pt.c (working copy) @@ -18987,14 +18987,19 @@ type_unification_real (tree tparms, if (DECL_P (parm)) input_location = DECL_SOURCE_LOCATION (parm); arg = tsubst_template_arg (arg, full_targs, complain, NULL_TREE); - arg = convert_template_argument (parm, arg, full_targs, complain, - i, NULL_TREE); + if (!uses_template_parms (arg)) + arg = convert_template_argument (parm, arg, full_targs, complain, + i, NULL_TREE); + else if (saw_undeduced < 2) + arg = NULL_TREE; + else + arg = error_mark_node; input_location = save_loc; *checks = get_deferred_access_checks (); pop_deferring_access_checks (); if (arg == error_mark_node) return 1; - else + else if (arg) { TREE_VEC_ELT (targs, i) = arg; /* The position of the first default template argument, @@ -19002,7 +19007,6 @@ type_unification_real (tree tparms, Record that. */ if (!NON_DEFAULT_TEMPLATE_ARGS_COUNT (targs)) SET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (targs, i); - continue; } } Index: testsuite/g++.dg/cpp0x/pr78701.C =================================================================== --- testsuite/g++.dg/cpp0x/pr78701.C (revision 0) +++ testsuite/g++.dg/cpp0x/pr78701.C (working copy) @@ -0,0 +1,9 @@ +// PR c++/58707 +// { dg-do compile { target c++11 } } + +// ICE during deduction of default parms + +template + void f(T x) {} + +template void f (int);