From patchwork Sun Dec 30 16:08:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1019438 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-493199-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="wF35maks"; 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 43SQNQ2BWxz9sB7 for ; Mon, 31 Dec 2018 03:08:38 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=Z5oOrx17laEVbjPuhlTjHat/3ytJTC3X8zHPzkgGzTvDWYhWXmTn2 KD3/T0VO/Pbo18PhCXaGjv5aEEJ5q++Pcu9PKlxFOIrrYfVrJlSqMoe+nVJ3JPQq DonJ6GFKxzZu4k9kNiqc1Gx8WVzTKJQoF3+uwvq3LhQV3GH4R1MDJk= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=t6dZBe7svbmfhWH47vEW/35KfuI=; b=wF35maksK+CrG/21HKb5 DNYucdOlknzITnoDiFwuqiBI2+Tk7HhahJrlRctxU3fU1G4hQNtrKiym0MUnQ1Q3 zezPfAuBta3/TW0sYEPpGYHiVP7D0tLpZigvm5qJzeEgVGdQ88oHdeyQxFXYWz54 GTV5JU2KAe9YYLjf19nEZrQ= Received: (qmail 98096 invoked by alias); 30 Dec 2018 16:08:31 -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 98086 invoked by uid 89); 30 Dec 2018 16:08:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 30 Dec 2018 16:08:29 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 76CB85F789 for ; Sun, 30 Dec 2018 16:08:28 +0000 (UTC) Received: from redhat.com (ovpn-120-115.rdu2.redhat.com [10.10.120.115]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0887360123; Sun, 30 Dec 2018 16:08:27 +0000 (UTC) Date: Sun, 30 Dec 2018 11:08:33 -0500 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: C++ PATCH for c++/88631, CTAD failing for value-initialization Message-ID: <20181230160833.GU21364@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) This PR points out that while we are able to deduce the template arguments for A{}, we fail for A(). For A{}, the deduction happens in finish_compound_literal: 2789 if (tree anode = type_uses_auto (type)) 2790 if (CLASS_PLACEHOLDER_TEMPLATE (anode)) 2791 { 2792 type = do_auto_deduction (type, compound_literal, anode, complain, 2793 adc_variable_type) and for A() in build_functional_cast, but there we always give error if there are no parameters. That is wrong because even though there are no arguments to deduce from, we might still be able to deduce from default template arguments as in the test. Fixed thus; I'm passing tf_none if there are no params because we don't want to give redundant diagnostics if the deduction fails. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2018-12-30 Marek Polacek PR c++/88631 - CTAD failing for value-initialization. * typeck2.c (build_functional_cast): Try deducing the template arguments even if there are no arguments to deduce from. * g++.dg/cpp1z/class-deduction59.C: New test. diff --git gcc/cp/typeck2.c gcc/cp/typeck2.c index cc9bf02439b..206a87b94a1 100644 --- gcc/cp/typeck2.c +++ gcc/cp/typeck2.c @@ -2147,9 +2147,18 @@ build_functional_cast (tree exp, tree parms, tsubst_flags_t complain) } else if (!parms) { - if (complain & tf_error) - error ("cannot deduce template arguments for %qT from ()", anode); - return error_mark_node; + /* Even if there are no parameters, we might be able to deduce from + default template arguments. Pass TF_NONE so that we don't + generate redundant diagnostics. */ + type = do_auto_deduction (type, parms, anode, tf_none, + adc_variable_type); + if (type == error_mark_node) + { + if (complain & tf_error) + error ("cannot deduce template arguments for %qT from ()", + anode); + return error_mark_node; + } } else type = do_auto_deduction (type, parms, anode, complain, diff --git gcc/testsuite/g++.dg/cpp1z/class-deduction59.C gcc/testsuite/g++.dg/cpp1z/class-deduction59.C new file mode 100644 index 00000000000..129d723d07c --- /dev/null +++ gcc/testsuite/g++.dg/cpp1z/class-deduction59.C @@ -0,0 +1,12 @@ +// PR c++/88631 +// { dg-do compile { target c++17 } } + +template +class A { }; + +int main() +{ + auto x = A(); + auto x2 = A{}; + A y; +}