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++/99287] std::source_location::function_name breaks constexpr
Date: Fri, 05 Mar 2021 15:30:56 +0000	[thread overview]
Message-ID: <bug-99287-4-tujucpvssq@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-99287-4@http.gcc.gnu.org/bugzilla/>

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
IIUC, those two types are actually the same, it's just that one of them was
obtained through the char_type alias, and it seems debug_tree prefers to show
the name of the alias when the type came from one.

It seems the issue ultimately is in cxx_eval_increment_expression: during
evaluation of ++__first with __first = &"mystr"[n] + m and with lval=false,
since cxx_fold_pointer_plus_expression and not fold_build2 is responsible for
simplifying this POINTER_PLUS_EXPR to &"mystr"[n+m], returning 'mod' actually
returns the unreduced &"mystr"[n] + m rather than the reduced &"mystr"[n+m]
that we obtain as part of constexpr evaluation of the temporary MODIFY_EXPR. 
This unreduced return value of cxx_eval_increment interfers with later
constexpr evaluation, e.g. folding of the POINTER_DIFF_EXPR.

I'm testing the following which updates 'mod' with the result of evaluation of
the MODIFY_EXPR:

--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -5582,20 +5582,14 @@ cxx_eval_increment_expression (const constexpr_ctx
*ctx, tree t,
   /* Storing the modified value.  */
   tree store = build2_loc (cp_expr_loc_or_loc (t, input_location),
                           MODIFY_EXPR, type, op, mod);
-  cxx_eval_constant_expression (ctx, store,
-                               true, non_constant_p, overflow_p);
+  mod = cxx_eval_constant_expression (ctx, store, false,
+                                     non_constant_p, overflow_p);
   ggc_free (store);

   /* And the value of the expression.  */

  parent reply	other threads:[~2021-03-05 15:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-26 12:29 [Bug c++/99287] New: " nickgray0 at brown dot edu
2021-02-26 15:46 ` [Bug c++/99287] " jakub at gcc dot gnu.org
2021-02-26 15:49 ` jakub at gcc dot gnu.org
2021-03-05 15:30 ` ppalka at gcc dot gnu.org [this message]
2021-03-05 15:39 ` jakub at gcc dot gnu.org
2021-03-05 15:57 ` jakub at gcc dot gnu.org
2021-03-05 16:08 ` ppalka at gcc dot gnu.org
2021-03-06 22:10 ` cvs-commit at gcc dot gnu.org
2021-03-06 22:12 ` ppalka 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-99287-4-tujucpvssq@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).