public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/88174] Make __real__ += __val usable in constexpr context.
       [not found] <bug-88174-4@http.gcc.gnu.org/bugzilla/>
@ 2022-06-08  7:16 ` pinskia at gcc dot gnu.org
  2022-06-08 15:37 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-06-08  7:16 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |zhonghao at pku dot org.cn

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 105882 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/88174] Make __real__ += __val usable in constexpr context.
       [not found] <bug-88174-4@http.gcc.gnu.org/bugzilla/>
  2022-06-08  7:16 ` [Bug c++/88174] Make __real__ += __val usable in constexpr context pinskia at gcc dot gnu.org
@ 2022-06-08 15:37 ` jakub at gcc dot gnu.org
  2022-08-07  8:09 ` cvs-commit at gcc dot gnu.org
  2022-08-10 10:58 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-08 15:37 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 53104
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53104&action=edit
gcc13-pr88174.patch

Untested fix.

Also fixes e.g.:
#include <complex>

constexpr bool
foo ()
{
  std::complex<double> a (1.0, 2.0);
  a += 3.0;
  a.real (6.0);
  return a.real () == 6.0 && a.imag () == 2.0;
}

static_assert (foo ());

with -std=c++20 which failed before.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/88174] Make __real__ += __val usable in constexpr context.
       [not found] <bug-88174-4@http.gcc.gnu.org/bugzilla/>
  2022-06-08  7:16 ` [Bug c++/88174] Make __real__ += __val usable in constexpr context pinskia at gcc dot gnu.org
  2022-06-08 15:37 ` jakub at gcc dot gnu.org
@ 2022-08-07  8:09 ` cvs-commit at gcc dot gnu.org
  2022-08-10 10:58 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-08-07  8:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:190776773516955df480bfa75731c34c5aaf2306

commit r13-1983-g190776773516955df480bfa75731c34c5aaf2306
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sun Aug 7 10:07:38 2022 +0200

    c++: Add support for __real__/__imag__ modifications in constant
expressions [PR88174]

    We claim we support P0415R1 (constexpr complex), but e.g.
     #include <complex>

    constexpr bool
    foo ()
    {
      std::complex<double> a (1.0, 2.0);
      a += 3.0;
      a.real (6.0);
      return a.real () == 6.0 && a.imag () == 2.0;
    }

    static_assert (foo ());

    fails with
    test.C:12:20: error: non-constant condition for static assertion
       12 | static_assert (foo ());
          |                ~~~~^~
    test.C:12:20:   in âconstexprâ expansion of âfoo()â
    test.C:8:10:   in âconstexprâ expansion of
âa.std::complex<double>::real(6.0e+0)â
    test.C:12:20: error: modification of â__real__
a.std::complex<double>::_M_valueâ is not a constant expression

    The problem is we don't handle REALPART_EXPR and IMAGPART_EXPR
    in cxx_eval_store_expression.
    The following patch attempts to support it (with a requirement
    that those are the outermost expressions, ARRAY_REF/COMPONENT_REF
    etc. are just not possible on the result of these, BIT_FIELD_REF
    would be theoretically possible if trying to extract some bits
    from one part of a complex int, but I don't see how it could appear
    in the FE trees.

    For these references, the code handles value being COMPLEX_CST,
    COMPLEX_EXPR or CONSTRUCTOR_NO_CLEARING empty CONSTRUCTOR (what we use
    to represent uninitialized values for C++20 and later) and the
    code starts by rewriting it to COMPLEX_EXPR, so that we can freely
    adjust the individual parts and later on possibly optimize it back
    to COMPLEX_CST if both halves are constant.

    2022-08-07  Jakub Jelinek  <jakub@redhat.com>

            PR c++/88174
            * constexpr.cc (cxx_eval_store_expression): Handle REALPART_EXPR
            and IMAGPART_EXPR.  Change ctors from releasing_vec to
            auto_vec<tree *>, adjust all uses.  For !preeval, update ctors
            vector.

            * g++.dg/cpp1y/constexpr-complex1.C: New test.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/88174] Make __real__ += __val usable in constexpr context.
       [not found] <bug-88174-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2022-08-07  8:09 ` cvs-commit at gcc dot gnu.org
@ 2022-08-10 10:58 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-08-10 10:58 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Backport doesn't work in 12 for multiple reasons and it isn't a regression
anyway, so fixed for 13+.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-08-10 10:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-88174-4@http.gcc.gnu.org/bugzilla/>
2022-06-08  7:16 ` [Bug c++/88174] Make __real__ += __val usable in constexpr context pinskia at gcc dot gnu.org
2022-06-08 15:37 ` jakub at gcc dot gnu.org
2022-08-07  8:09 ` cvs-commit at gcc dot gnu.org
2022-08-10 10:58 ` jakub at gcc dot gnu.org

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).