From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 0B82C3858C36; Mon, 23 Jan 2023 19:09:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B82C3858C36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674500997; bh=5gcVeCxUzud88kAqVo5eJxjI7w4HpjG0FVyMATh1y48=; h=From:To:Subject:Date:From; b=O+MIPG61eTc4mWdsia8fJuylisywfpPSPe4VVLxO6h+2ELrNcnxuEj32byIB5sgkt /Nbg00pRRToKE+AiNJsoupSHAKXj7OO0fwRmgwCecy6uH3YPiRSXeXkVPRBIfvnFYW l0unG84H38W0ZC1p9S367XZz9pJkmRrA4hkNyS5I= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5310] c++: result location and explicit inst [PR108496] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/trunk X-Git-Oldrev: c3c6c307792026705fe0398f5ee399f7668fed1b X-Git-Newrev: 4b125d01a5d5e601961419396332b74eea2219bb Message-Id: <20230123190957.0B82C3858C36@sourceware.org> Date: Mon, 23 Jan 2023 19:09:57 +0000 (GMT) List-Id: https://gcc.gnu.org/g:4b125d01a5d5e601961419396332b74eea2219bb commit r13-5310-g4b125d01a5d5e601961419396332b74eea2219bb Author: Jason Merrill Date: Mon Jan 23 13:33:07 2023 -0500 c++: result location and explicit inst [PR108496] 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. Diff: --- gcc/cp/decl.cc | 6 +++++- gcc/testsuite/g++.dg/template/explicit-instantiation5.C | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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);