public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ppalka at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/114393] [14 regression] over eager "invalid use of void expression" ? since r14-2170-g4cf64d9cc2faf4
Date: Fri, 12 Apr 2024 19:08:46 +0000	[thread overview]
Message-ID: <bug-114393-4-LLdMrwM5fO@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-114393-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114393

--- Comment #6 from Patrick Palka <ppalka at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:081c1e93d56d35c7314ed68e6d87628b430de917

commit r14-9938-081c1e93d56d35c7314ed68e6d87628b430de917
Author: Patrick Palka <ppalka@redhat.com>

c++: templated substitution into lambda-expr [PR114393]

The below testcases use a lambda-expr as a template argument and they
all trip over the below added tsubst_lambda_expr sanity check ultimately
because current_template_parms is empty which causes push_template_decl
to return error_mark_node from the call to begin_lambda_type.  Were it
not for the sanity check this silent error_mark_node result leads to
nonsensical errors down the line, or silent breakage.

In the first testcase, we hit this assert during instantiation of the
dependent alias template-id c1_t<_Data> from instantiate_template, which
clears current_template_parms via push_to_top_level.  Similar story for
the second testcase.  For the third testcase we hit the assert during
partial instantiation of the member template from instantiate_class_template
which similarly calls push_to_top_level.

These testcases illustrate that templated substitution into a lambda-expr
is not always possible, in particular when we lost the relevant template
context.  I experimented with recovering the template context by making
tsubst_lambda_expr fall back to using scope_chain->prev->template_parms if
current_template_parms is empty which worked but seemed like a hack.  I
also experimented with preserving the template context by keeping
current_template_parms set during instantiate_template for a dependent
specialization which also worked but it's at odds with the fact that we
cache dependent specializations (and so they should be independent of
the template context).

So instead of trying to make such substitution work, this patch uses the
extra-args mechanism to defer templated substitution into a lambda-expr
when we lost the relevant template context.

        PR c++/114393
        PR c++/107457
        PR c++/93595

gcc/cp/ChangeLog:

        * cp-tree.h (LAMBDA_EXPR_EXTRA_ARGS): Define.
        (tree_lambda_expr::extra_args): New field.
        * module.cc (trees_out::core_vals) <case LAMBDA_EXPR>: Stream
        LAMBDA_EXPR_EXTRA_ARGS.
        (trees_in::core_vals) <case LAMBDA_EXPR>: Likewise.
        * pt.cc (has_extra_args_mechanism_p): Return true for LAMBDA_EXPR.
        (tree_extra_args): Handle LAMBDA_EXPR.
        (tsubst_lambda_expr): Use LAMBDA_EXPR_EXTRA_ARGS to defer templated
        substitution into a lambda-expr if we lost the template context.
        Add sanity check for error_mark_node result from begin_lambda_type.

gcc/testsuite/ChangeLog:

        * g++.dg/cpp2a/lambda-targ2.C: New test.
        * g++.dg/cpp2a/lambda-targ3.C: New test.
        * g++.dg/cpp2a/lambda-targ4.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>

  parent reply	other threads:[~2024-04-12 19:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-19 11:09 [Bug c++/114393] New: over eager "invalid use of void expression" ? prlw1 at cam dot ac.uk
2024-03-19 11:29 ` [Bug c++/114393] [14 regression] " redi at gcc dot gnu.org
2024-03-19 11:32 ` redi at gcc dot gnu.org
2024-03-19 11:56 ` [Bug c++/114393] [14 regression] over eager "invalid use of void expression" ? since r14-2170-g4cf64d9cc2faf4 rguenth at gcc dot gnu.org
2024-03-19 22:42 ` pinskia at gcc dot gnu.org
2024-03-20  3:51 ` pinskia at gcc dot gnu.org
2024-03-20  4:04 ` pinskia at gcc dot gnu.org
2024-03-25 19:05 ` ppalka at gcc dot gnu.org
2024-03-29 23:49 ` law at gcc dot gnu.org
2024-04-12 19:08 ` ppalka at gcc dot gnu.org [this message]
2024-04-12 19:09 ` ppalka at gcc dot gnu.org
2024-04-12 19:11 ` ppalka at gcc dot gnu.org
2024-04-14 19:27 ` prlw1 at cam dot ac.uk

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=bug-114393-4-LLdMrwM5fO@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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: link
Be 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).