public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110463] New: Mutable subobject is usable in a constant expression
@ 2023-06-28 17:15 fchelnokov at gmail dot com
  2023-06-28 17:29 ` [Bug c++/110463] [13/14 Regression] " ppalka at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: fchelnokov at gmail dot com @ 2023-06-28 17:15 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110463
           Summary: Mutable subobject is usable in a constant expression
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The following program is invalid per
https://timsong-cpp.github.io/cppwp/n4861/expr.const#4.8 (An object or
reference is usable in constant expressions if it is ... a non-mutable
subobject)

struct U {
    mutable int x = 2;
};

int main() {
    constexpr U u{};
    u.x = 1;
    static_assert( u.x == 2 ); // must fail, but ok in GCC
}

but GCC accepts it. Online demo: https://gcc.godbolt.org/z/n8MYzhbad

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

* [Bug c++/110463] [13/14 Regression] Mutable subobject is usable in a constant expression
  2023-06-28 17:15 [Bug c++/110463] New: Mutable subobject is usable in a constant expression fchelnokov at gmail dot com
@ 2023-06-28 17:29 ` ppalka at gcc dot gnu.org
  2023-06-29 20:10 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-06-28 17:29 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.2
             Status|UNCONFIRMED                 |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
      Known to fail|                            |13.1.0, 14.0
     Ever confirmed|0                           |1
           Keywords|                            |accepts-invalid
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=92505
   Last reconfirmed|                            |2023-06-28
            Summary|Mutable subobject is usable |[13/14 Regression] Mutable
                   |in a constant expression    |subobject is usable in a
                   |                            |constant expression
                 CC|                            |ppalka at gcc dot gnu.org
      Known to work|                            |12.3.0

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Confirmed, started with r13-2701-g7107ea6fb933f1

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

* [Bug c++/110463] [13/14 Regression] Mutable subobject is usable in a constant expression
  2023-06-28 17:15 [Bug c++/110463] New: Mutable subobject is usable in a constant expression fchelnokov at gmail dot com
  2023-06-28 17:29 ` [Bug c++/110463] [13/14 Regression] " ppalka at gcc dot gnu.org
@ 2023-06-29 20:10 ` cvs-commit at gcc dot gnu.org
  2023-07-01  1:28 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-29 20:10 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:fd8a1be04d4cdbfefea457b99ed8404d77b35dd6

commit r14-2198-gfd8a1be04d4cdbfefea457b99ed8404d77b35dd6
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Jun 29 16:02:04 2023 -0400

    c++: unpropagated CONSTRUCTOR_MUTABLE_POISON [PR110463]

    Here we're incorrectly accepting the mutable member accesses because
    cp_fold neglects to propagate CONSTRUCTOR_MUTABLE_POISON when folding a
    CONSTRUCTOR.

            PR c++/110463

    gcc/cp/ChangeLog:

            * cp-gimplify.cc (cp_fold) <case CONSTRUCTOR>: Propagate
            CONSTRUCTOR_MUTABLE_POISON.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/constexpr-mutable6.C: New test.

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

* [Bug c++/110463] [13/14 Regression] Mutable subobject is usable in a constant expression
  2023-06-28 17:15 [Bug c++/110463] New: Mutable subobject is usable in a constant expression fchelnokov at gmail dot com
  2023-06-28 17:29 ` [Bug c++/110463] [13/14 Regression] " ppalka at gcc dot gnu.org
  2023-06-29 20:10 ` cvs-commit at gcc dot gnu.org
@ 2023-07-01  1:28 ` cvs-commit at gcc dot gnu.org
  2023-07-01  1:29 ` ppalka at gcc dot gnu.org
  2023-07-01 18:06 ` fchelnokov at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-01  1:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:8f2cafc03f645748109291710157fdeceac32ee1

commit r13-7516-g8f2cafc03f645748109291710157fdeceac32ee1
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Jun 29 16:02:04 2023 -0400

    c++: unpropagated CONSTRUCTOR_MUTABLE_POISON [PR110463]

    Here we're incorrectly accepting the mutable member accesses because
    cp_fold neglects to propagate CONSTRUCTOR_MUTABLE_POISON when folding a
    CONSTRUCTOR.

            PR c++/110463

    gcc/cp/ChangeLog:

            * cp-gimplify.cc (cp_fold) <case CONSTRUCTOR>: Propagate
            CONSTRUCTOR_MUTABLE_POISON.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/constexpr-mutable6.C: New test.

    (cherry picked from commit fd8a1be04d4cdbfefea457b99ed8404d77b35dd6)

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

* [Bug c++/110463] [13/14 Regression] Mutable subobject is usable in a constant expression
  2023-06-28 17:15 [Bug c++/110463] New: Mutable subobject is usable in a constant expression fchelnokov at gmail dot com
                   ` (2 preceding siblings ...)
  2023-07-01  1:28 ` cvs-commit at gcc dot gnu.org
@ 2023-07-01  1:29 ` ppalka at gcc dot gnu.org
  2023-07-01 18:06 ` fchelnokov at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-07-01  1:29 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Should be fixed for GCC 13.2, thanks for the bug report.

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

* [Bug c++/110463] [13/14 Regression] Mutable subobject is usable in a constant expression
  2023-06-28 17:15 [Bug c++/110463] New: Mutable subobject is usable in a constant expression fchelnokov at gmail dot com
                   ` (3 preceding siblings ...)
  2023-07-01  1:29 ` ppalka at gcc dot gnu.org
@ 2023-07-01 18:06 ` fchelnokov at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: fchelnokov at gmail dot com @ 2023-07-01 18:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Fedor Chelnokov <fchelnokov at gmail dot com> ---
Thanks a lot for a very quick fix!

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

end of thread, other threads:[~2023-07-01 18:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-28 17:15 [Bug c++/110463] New: Mutable subobject is usable in a constant expression fchelnokov at gmail dot com
2023-06-28 17:29 ` [Bug c++/110463] [13/14 Regression] " ppalka at gcc dot gnu.org
2023-06-29 20:10 ` cvs-commit at gcc dot gnu.org
2023-07-01  1:28 ` cvs-commit at gcc dot gnu.org
2023-07-01  1:29 ` ppalka at gcc dot gnu.org
2023-07-01 18:06 ` fchelnokov at gmail dot com

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