public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-7516] c++: unpropagated CONSTRUCTOR_MUTABLE_POISON [PR110463]
@ 2023-07-01  1:28 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2023-07-01  1:28 UTC (permalink / raw)
  To: gcc-cvs

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)

Diff:
---
 gcc/cp/cp-gimplify.cc                           |  2 ++
 gcc/testsuite/g++.dg/cpp0x/constexpr-mutable6.C | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
index 216a6231d6f..28a92ad547b 100644
--- a/gcc/cp/cp-gimplify.cc
+++ b/gcc/cp/cp-gimplify.cc
@@ -3079,6 +3079,8 @@ cp_fold (tree x, fold_flags_t flags)
 	    x = build_constructor (TREE_TYPE (x), nelts);
 	    CONSTRUCTOR_PLACEHOLDER_BOUNDARY (x)
 	      = CONSTRUCTOR_PLACEHOLDER_BOUNDARY (org_x);
+	    CONSTRUCTOR_MUTABLE_POISON (x)
+	      = CONSTRUCTOR_MUTABLE_POISON (org_x);
 	  }
 	if (VECTOR_TYPE_P (TREE_TYPE (x)))
 	  x = fold (x);
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-mutable6.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-mutable6.C
new file mode 100644
index 00000000000..2c946e388ab
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-mutable6.C
@@ -0,0 +1,18 @@
+// PR c++/110463
+// { dg-do compile { target c++11 } }
+
+struct U {
+  mutable int x = 1;
+};
+
+struct V {
+  mutable int y = 1+1;
+};
+
+int main() {
+  constexpr U u = {};
+  constexpr int x = u.x; // { dg-error "mutable" }
+
+  constexpr V v = {};
+  constexpr int y = v.y; // { dg-error "mutable" }
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-07-01  1:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-01  1:28 [gcc r13-7516] c++: unpropagated CONSTRUCTOR_MUTABLE_POISON [PR110463] Patrick Palka

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