aboutsummaryrefslogtreecommitdiff
path: root/clang/test/AST/ByteCode/cxx11.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/AST/ByteCode/cxx11.cpp')
-rw-r--r--clang/test/AST/ByteCode/cxx11.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/clang/test/AST/ByteCode/cxx11.cpp b/clang/test/AST/ByteCode/cxx11.cpp
index bb8aca2..08caca0 100644
--- a/clang/test/AST/ByteCode/cxx11.cpp
+++ b/clang/test/AST/ByteCode/cxx11.cpp
@@ -318,3 +318,45 @@ namespace PR19010 {
};
void test() { constexpr Test t; }
}
+
+namespace ReadMutableInCopyCtor {
+ struct G {
+ struct X {};
+ union U { X a; };
+ mutable U u; // both-note {{declared here}}
+ };
+ constexpr G g1 = {};
+ constexpr G g2 = g1; // both-error {{must be initialized by a constant expression}} \
+ // both-note {{read of mutable member 'u'}} \
+ // both-note {{in call to 'G(g1)'}}
+}
+
+namespace GH150709 {
+ struct C { };
+ struct D : C {
+ constexpr int f() const { return 1; };
+ };
+ struct E : C { };
+ struct F : D { };
+ struct G : E { };
+
+ constexpr C c1, c2[2];
+ constexpr D d1, d2[2];
+ constexpr E e1, e2[2];
+ constexpr F f;
+ constexpr G g;
+
+ constexpr auto mp = static_cast<int (C::*)() const>(&D::f);
+
+ // sanity checks for fix of GH150709 (unchanged behavior)
+ static_assert((c1.*mp)() == 1, ""); // both-error {{constant expression}}
+ static_assert((d1.*mp)() == 1, "");
+ static_assert((f.*mp)() == 1, "");
+ static_assert((c2[0].*mp)() == 1, ""); // ref-error {{constant expression}}
+ static_assert((d2[0].*mp)() == 1, "");
+
+ // incorrectly undiagnosed before fix of GH150709
+ static_assert((e1.*mp)() == 1, ""); // ref-error {{constant expression}}
+ static_assert((e2[0].*mp)() == 1, ""); // ref-error {{constant expression}}
+ static_assert((g.*mp)() == 1, ""); // ref-error {{constant expression}}
+}