From patchwork Mon Jan 23 19:09:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 47336 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1772475wrn; Mon, 23 Jan 2023 11:10:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXvZ4dGVsTs9R1maLMNWDoHCd4OXwMx1CtIifWO3EpLWCno1mIjIIYQuWIdsWCxj6Fp5dMQd X-Received: by 2002:a05:6402:3214:b0:496:37c9:b8e6 with SMTP id g20-20020a056402321400b0049637c9b8e6mr30636171eda.8.1674501031466; Mon, 23 Jan 2023 11:10:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674501031; cv=none; d=google.com; s=arc-20160816; b=pmp87CNVqHSMCPB9m5UZ+6yfdYudD8vweH1BdITxSVztTjXEk4unfYKUtA2qc+CjWF CTdxR2DQZNkAjyS3DjDecvKsQCia1GNVd/1JVFrhV/zznDVFU+65XOB4kvMbFi5PxqOs h+gS+ovcZGfYM9xHXIczQPqsiBzGc+hsFLArh+FHrSF7nYm2zHrNwf+GJ0lMbjJbSdR1 yyf1rgsmpw+xxkNxJVmWVLqNVgv541BWLAq5BSSQWXltsCGF1JEWBPm6MS3UaCHr6/is 2Rb6ArMrPdt55nchPsa9xJO560olousjtbGqxP9CaTK1xP4SSv/cNUETQ8hpFx6oRgiq LEuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=sw50UKDCpBQyb2DW5VluTPzEJNOUCdkkkUZgXr5QFFc=; b=rzl4+DKrC0W/W/wlVdY5ZKWl1ELaeQW6GsrDog4yjsihPv94ZFcGmFuvBwZj1FFACV UrZM7MMf1r51ZbLJyFh8oARvK9KelOkJlES/UWvy7rTwfd/IO+qqYwRfumdOmG6RNA0T CpWhDd7Shr/S4x67LaHWnlXC649NJTnExXbQVJJdtytNMYyXvpEF5S7mwGW/JW/wl3A6 bVNwIlIEiTU53NA+/uvfRKpvjUgZ0Qib71PgDCZ7byo6yMOvKYjiwc8ld9v0bynM8abE 5oLdpn6J0diW2oqaF2+zX3O1F87r5PPkpAElnYHUPfDE/qXAxlJ7zE7t1UJHTfIk+r7s 6HFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=c1+qrQkb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id oz16-20020a1709077d9000b0087766403ebcsi19494903ejc.850.2023.01.23.11.10.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 11:10:31 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=c1+qrQkb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D28E3858C2F for ; Mon, 23 Jan 2023 19:10:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D28E3858C2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674501027; bh=sw50UKDCpBQyb2DW5VluTPzEJNOUCdkkkUZgXr5QFFc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=c1+qrQkbOnAFqdylw4M/fw6Q8q04ikJhsMw96sz1AbDQQtqCYMMQ3U8P0MoGra0VE nlR55jzEuljUGHDMFf8hPjwS1LyMrXV9no/OhSguI9wKSA7wtItjjnj5IDXZ4XYSoA yhqwsO5GCVwwp9lA+PynG2l12Oenyj+/mcYYWR7Q= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 1DE6C3858D33 for ; Mon, 23 Jan 2023 19:09:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1DE6C3858D33 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-630-dWLQo74tNuqFCMYKBWDdoA-1; Mon, 23 Jan 2023 14:09:41 -0500 X-MC-Unique: dWLQo74tNuqFCMYKBWDdoA-1 Received: by mail-qt1-f200.google.com with SMTP id hf20-20020a05622a609400b003abcad051d2so4886920qtb.12 for ; Mon, 23 Jan 2023 11:09:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sw50UKDCpBQyb2DW5VluTPzEJNOUCdkkkUZgXr5QFFc=; b=MAG5Hq2H4MyTv+ZjA6Xg5btI9e0ed0cH7Xo11xbgON2DMwrXQpfluCJSyiOPq8Y6nn +N9AmWempQq/77oOorfFi40MM10/WYFGzjdptgyXVDsg4w+aIohUE14MS7rnHjUcvNDl RE5WzLNjnwURdSYPlzUCOdmHXlkxXZVpeboS0uB+vhbBsHrSAd1fYhx/Tkw9GkbYXZYs 3t2DUDYGnw7bidmgFEk21gMk7ZK7fmZ4YishxwjPJpjWGK+8mrsSOj2TupgLkoMUoSPD QcloWxGtZZrSRTYmHzvgfUU2KvLrfTnJnLHP9J56GLdQdkPpKqh0IvCOFsLPYz5NAm9H g0KA== X-Gm-Message-State: AFqh2kqDlg/ejjwHsfGPrIQh13Y41Jcnd1TUqVsdiVHyDSYKszNXp+l5 sRSAwOwC0uG3KEKnkYQeBLCC2libq7Uwg5pqK3S9itOGncEqWWaxsIQIHsWoU58U3rHFdheOYvZ 8FMqNPIa4GvEd9c1SJ+MZSuyWSzSpOiB0Xq8LWMYyWTUQL0NDS/wb5oYCBNmoAAh2RA== X-Received: by 2002:a05:622a:1f16:b0:3a6:a4ed:7c42 with SMTP id ca22-20020a05622a1f1600b003a6a4ed7c42mr39885988qtb.54.1674500980684; Mon, 23 Jan 2023 11:09:40 -0800 (PST) X-Received: by 2002:a05:622a:1f16:b0:3a6:a4ed:7c42 with SMTP id ca22-20020a05622a1f1600b003a6a4ed7c42mr39885954qtb.54.1674500980264; Mon, 23 Jan 2023 11:09:40 -0800 (PST) Received: from jason.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id bw5-20020a05622a098500b003b64f1b1f40sm8837699qtb.40.2023.01.23.11.09.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 11:09:39 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: result location and explicit inst [PR108496] Date: Mon, 23 Jan 2023 14:09:36 -0500 Message-Id: <20230123190936.4161568-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755841593754082094?= X-GMAIL-MSGID: =?utf-8?q?1755841593754082094?= Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- In r13-4469 we started to build the RESULT_DECL in grokdeclarator, while we still know the location of the return type. But in this testcase, we hit that code again when parsing the explicit instantiation, and clobber the DECL_RESULT that was previously used in parsing the function. So, only set DECL_RESULT if it isn't already set. PR c++/108496 gcc/cp/ChangeLog: * decl.cc (grokdeclarator): Check whether DECL_RESULT is already set. gcc/testsuite/ChangeLog: * g++.dg/template/explicit-instantiation5.C: New test. --- gcc/cp/decl.cc | 6 +++++- .../g++.dg/template/explicit-instantiation5.C | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/template/explicit-instantiation5.C base-commit: 208c6678c25bd9a11e6c5911a4c123cb6b7f3d6e diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 75ddf8016b5..d606b31d7a7 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -14776,7 +14776,9 @@ grokdeclarator (const cp_declarator *declarator, { /* If we saw a return type, record its location. */ location_t loc = declspecs->locations[ds_type_spec]; - if (loc != UNKNOWN_LOCATION) + if (loc == UNKNOWN_LOCATION) + /* Build DECL_RESULT in start_preparsed_function. */; + else if (!DECL_RESULT (decl)) { tree restype = TREE_TYPE (TREE_TYPE (decl)); tree resdecl = build_decl (loc, RESULT_DECL, 0, restype); @@ -14784,6 +14786,8 @@ grokdeclarator (const cp_declarator *declarator, DECL_IGNORED_P (resdecl) = 1; DECL_RESULT (decl) = resdecl; } + else if (funcdef_flag) + DECL_SOURCE_LOCATION (DECL_RESULT (decl)) = loc; } /* Record constancy and volatility on the DECL itself . There's diff --git a/gcc/testsuite/g++.dg/template/explicit-instantiation5.C b/gcc/testsuite/g++.dg/template/explicit-instantiation5.C new file mode 100644 index 00000000000..7bc007c8107 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/explicit-instantiation5.C @@ -0,0 +1,15 @@ +// PR c++/108496 + +struct S { long a, b, c; } s; + +template +S foo (S); + +template <> +S +foo <0, long> (S) +{ + return s; +} + +template S foo <0, long> (S);