From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id DF8323858431; Thu, 7 Oct 2021 20:40:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DF8323858431 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-4238] c++: NTTP with array/function type after substitution [PR61355] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: 7f78718b7958f603d50d5c30fd8735d73900bd1f X-Git-Newrev: fba228e259dd5112851527f2dbb62c5601100985 Message-Id: <20211007204051.DF8323858431@sourceware.org> Date: Thu, 7 Oct 2021 20:40:51 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Oct 2021 20:40:52 -0000 https://gcc.gnu.org/g:fba228e259dd5112851527f2dbb62c5601100985 commit r12-4238-gfba228e259dd5112851527f2dbb62c5601100985 Author: Patrick Palka Date: Thu Oct 7 16:39:16 2021 -0400 c++: NTTP with array/function type after substitution [PR61355] We're performing the [temp.param]/10 adjustment at parse time but not also at substitution time. PR c++/61355 gcc/cp/ChangeLog: * pt.c (convert_template_argument): Perform array/function to pointer conversion on the substituted type of an NTTP. gcc/testsuite/ChangeLog: * g++.old-deja/g++.pt/nontype5.C: Adjust. * g++.dg/template/param6.C: New test. Diff: --- gcc/cp/pt.c | 4 ++++ gcc/testsuite/g++.dg/template/param6.C | 32 ++++++++++++++++++++++++++++ gcc/testsuite/g++.old-deja/g++.pt/nontype5.C | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 1e52aa757e1..009fe6db573 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -8530,6 +8530,10 @@ convert_template_argument (tree parm, else t = tsubst (t, args, complain, in_decl); + /* Perform array-to-pointer and function-to-pointer conversion + as per [temp.param]/10. */ + t = type_decays_to (t); + if (invalid_nontype_parm_type_p (t, complain)) return error_mark_node; diff --git a/gcc/testsuite/g++.dg/template/param6.C b/gcc/testsuite/g++.dg/template/param6.C new file mode 100644 index 00000000000..8306e753d70 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/param6.C @@ -0,0 +1,32 @@ +// PR c++/61355 +// Verify we perform array-to-pointer and function-to-pointer conversion +// on the substituted/deduced type of an NTTP. + +int f(); +int p[5]; + +namespace cpp98 { + template struct X; + typedef X ty1; + typedef X ty2; +} + +namespace cpp11 { +#if __cpp_variadic_templates + template struct X; + using ty1 = X; + using ty2 = X; +#endif +} + +namespace cpp17 { +#if __cpp_nontype_template_parameter_auto + template struct X; + using ty1 = X; + using ty2 = X

; + + template struct Y; + using ty3 = Y; + using ty4 = Y

; +#endif +} diff --git a/gcc/testsuite/g++.old-deja/g++.pt/nontype5.C b/gcc/testsuite/g++.old-deja/g++.pt/nontype5.C index 2678cf78a7d..e24dca43622 100644 --- a/gcc/testsuite/g++.old-deja/g++.pt/nontype5.C +++ b/gcc/testsuite/g++.old-deja/g++.pt/nontype5.C @@ -19,5 +19,5 @@ static int g() { return f(); } int f() { return 0; } int main() { -return B::g(); // { dg-error "" } could not convert arg +return B::g(); }