From d9e916d988bfa12d3283ea89f5ba9c79e119a83b Mon Sep 17 00:00:00 2001
From: Jason Merrill <jason@gcc.gnu.org>
Date: Wed, 23 Jan 2002 07:49:12 -0500
Subject: [PATCH] re PR c++/3331 (member pointer inherits const)

        PR c++/3331
        * init.c (resolve_offset_ref): Use build_indirect_ref.

[[Split portion of a mixed commit.]]

From-SVN: r49134.2
---
 gcc/testsuite/g++.dg/other/const2.C | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/other/const2.C

diff --git a/gcc/testsuite/g++.dg/other/const2.C b/gcc/testsuite/g++.dg/other/const2.C
new file mode 100644
index 000000000000..25778fa73bce
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/const2.C
@@ -0,0 +1,22 @@
+// PR c++/3331: just because 'this' is readonly and bars[0].b is readonly
+// doesn't mean that the result of the member reference is readonly.
+
+struct foo
+{
+  int a;
+
+  struct bar
+  { int foo::* b ;};
+
+  static const bar bars[];
+
+  int bad ()
+  {
+    this->*(bars[0].b) = 42; // { dg-bogus "read-only" "" }
+  }
+};
+
+const foo::bar foo::bars[] = { { &foo::a } };
+
+int main ()
+{ }
-- 
GitLab