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++/104620] FAIL: g++.dg/cpp23/consteval-if2.C  -std=gnu++20  (test for errors)
Date: Thu, 24 Mar 2022 13:31:56 +0000	[thread overview]
Message-ID: <bug-104620-4-9UmxpamnL4@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-104620-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Some context: consider the simplified/extended C++20 testcase (the consteval-if
seems to be a red herring):

consteval int foo(int x) { return x; }

template<class>
void bar(int x)
{
  constexpr int y = 0;
  foo(8 * x); // #1
  foo(8 * y); // #2
}

Before r12-7264, we would indeed correctly reject #1 ahead of time (which has a
non-constant arg), but we would also incorrectly reject #2 (which has a
constant arg), because both arguments are wrapped in NON_DEPENDENT_EXPR which
cxx_eval_constant_expr considers to be always non-constant.  So essentially we
used to reject the two now-failing tests in consteval-if2.C only by accident.

After r12-7264, is_constant_expr returns false for NON_DEPENDENT_EXPR
(mirroring cxx_eval_constant_expr) which in particular means that
fold_non_dependent_expr no longer tries to check a non-dependent consteval call
ahead of time if it has a "complex" argument (i.e. one that is wrapped in
NON_DEPENDENT_EXPR).  Thus we no longer reject #1 ahead of time, and we also no
longer incorrectly reject #2.  IMHO this is overall an improvement, since not
rejecting #1 ahead of time is a QoI issue, whereas rejecting #2 is a
correctness issue.  This also fixed PR103443 for a similar reason.

(In reply to Jakub Jelinek from comment #3)
> So, either build_non_dependent_arg should be made smarter and not wrap even
> simple arithmetics etc. where no C++ template-ish trees appear inside of it
> and everything is like in normal non-template-ish code, or we should
> reconsider
> the r12-7264 case because clearly often we can handle NON_DEPENDENT_EXPR
> just fine.

I wonder if we can get rid of NON_DEPENDENT_EXPR entirely?  I'm not sure if
it's at all necessary anymore.  Or perhaps we could change tsubst /
is_constant_expr / eval_constant_expr to actually look through
NON_DEPENDENT_EXPR.  These ideas seem out of scope for GCC 12 though :/

  parent reply	other threads:[~2022-03-24 13:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-21 19:38 [Bug c++/104620] New: " danglin at gcc dot gnu.org
2022-03-23 18:04 ` [Bug c++/104620] " mpolacek at gcc dot gnu.org
2022-03-23 18:42 ` mpolacek at gcc dot gnu.org
2022-03-23 20:35 ` ppalka at gcc dot gnu.org
2022-03-24 12:21 ` jakub at gcc dot gnu.org
2022-03-24 13:29 ` jakub at gcc dot gnu.org
2022-03-24 13:31 ` ppalka at gcc dot gnu.org [this message]
2022-03-24 13:37 ` ppalka at gcc dot gnu.org
2022-03-24 14:29 ` ppalka at gcc dot gnu.org
2022-03-24 15:21 ` jason at gcc dot gnu.org
2022-03-24 15:42 ` cvs-commit at gcc dot gnu.org
2022-03-24 17:19 ` ppalka at gcc dot gnu.org
2022-03-26 23:01 ` jason at gcc dot gnu.org
2022-05-06  8:32 ` jakub at gcc dot gnu.org
2023-05-08 12:23 ` rguenth at gcc dot gnu.org

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-104620-4-9UmxpamnL4@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).