public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4761] c++: constantness of non-dependent NTTP argument [PR107437] Date: Sat, 17 Dec 2022 16:25:02 +0000 (GMT) [thread overview] Message-ID: <20221217162502.7B47C398641A@sourceware.org> (raw) https://gcc.gnu.org/g:982629bea416df976686467f235e09cb1a5531cc commit r13-4761-g982629bea416df976686467f235e09cb1a5531cc Author: Patrick Palka <ppalka@redhat.com> Date: Sat Dec 17 11:24:44 2022 -0500 c++: constantness of non-dependent NTTP argument [PR107437] Here we're rejecting the use of the lambda capture of 't' (of empty type) as a template argument ultimately because convert_nontype_argument checks constantness using is_constant_expression, which returns false for lambda captures since want_rval=false. But in this case I believe an lvalue-to-rvalue conversion of the argument is implied, so we should be using is_rvalue_constant_expression instead (which would return true here). However, it doesn't seem necessary to consider constantness at all when deciding whether to instantiate a non-dependent argument in convert_nontype_argument. So this patch gets rid of the problematic constantness test altogether, which incidentally also fixes the similar dg-ice'd testcase from PR87765. This is in line with a similar change we made to finish_decltype_type in r12-7564-gec0f53a3a542e7. PR c++/107437 PR c++/87765 gcc/cp/ChangeLog: * pt.cc (convert_nontype_argument): Relax is_nondep_const_expr test to !inst_dep_expr_p. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/lambda-generic-107437.C: New test. * g++.dg/cpp1z/constexpr-lambda26.C: Remove dg-ice. Diff: --- gcc/cp/pt.cc | 2 +- gcc/testsuite/g++.dg/cpp1y/lambda-generic-107437.C | 21 +++++++++++++++++++++ gcc/testsuite/g++.dg/cpp1z/constexpr-lambda26.C | 1 - 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index bc566ab702b..2516cca590e 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -7318,7 +7318,7 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) && has_value_dependent_address (expr)) /* If we want the address and it's value-dependent, don't fold. */; else if (processing_template_decl - && is_nondependent_constant_expression (expr)) + && !instantiation_dependent_expression_p (expr)) non_dep = true; if (error_operand_p (expr)) return error_mark_node; diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-107437.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-107437.C new file mode 100644 index 00000000000..f9b4e0187e2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-107437.C @@ -0,0 +1,21 @@ +// PR c++/107437 +// { dg-do compile { target c++14 } } + +struct integral_constant { + constexpr operator int() const { return 42; } +}; + +template<int N> +struct A { + static constexpr int value = N; +}; + +template<class T> +void f(T t) { + [=](auto) { + A<t> a; // { dg-bogus "constant" } + return a.value; + }(0); +} + +template void f(integral_constant); diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda26.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda26.C index 0cdb400d21c..e66cd1dee64 100644 --- a/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda26.C +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda26.C @@ -1,7 +1,6 @@ // PR c++/87765 // { dg-do compile { target c++17 } } // { dg-additional-options "-fchecking" } -// { dg-ice "cxx_eval_constant_expression" } template <int N> using foo = int;
reply other threads:[~2022-12-17 16:25 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221217162502.7B47C398641A@sourceware.org \ --to=ppalka@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).