aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2023-06-29 16:02:04 -0400
committerPatrick Palka <ppalka@redhat.com>2023-06-29 16:02:04 -0400
commitfd8a1be04d4cdbfefea457b99ed8404d77b35dd6 (patch)
treea70922d9f50369d258b60c20741981d10b509240
parent070a6bf0bdc6761ad77ac97404c98f00a7007d54 (diff)
downloadgcc-fd8a1be04d4cdbfefea457b99ed8404d77b35dd6.zip
gcc-fd8a1be04d4cdbfefea457b99ed8404d77b35dd6.tar.gz
gcc-fd8a1be04d4cdbfefea457b99ed8404d77b35dd6.tar.bz2
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.
-rw-r--r--gcc/cp/cp-gimplify.cc2
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-mutable6.C18
2 files changed, 20 insertions, 0 deletions
diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
index 853b1e4..f573419 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 0000000..2c946e3
--- /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" }
+}