diff options
Diffstat (limited to 'clang/test/AST/ByteCode')
-rw-r--r-- | clang/test/AST/ByteCode/cxx11.cpp | 30 | ||||
-rw-r--r-- | clang/test/AST/ByteCode/cxx2a.cpp | 14 |
2 files changed, 44 insertions, 0 deletions
diff --git a/clang/test/AST/ByteCode/cxx11.cpp b/clang/test/AST/ByteCode/cxx11.cpp index 7aecf23b..08caca0 100644 --- a/clang/test/AST/ByteCode/cxx11.cpp +++ b/clang/test/AST/ByteCode/cxx11.cpp @@ -330,3 +330,33 @@ namespace ReadMutableInCopyCtor { // 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}} +} diff --git a/clang/test/AST/ByteCode/cxx2a.cpp b/clang/test/AST/ByteCode/cxx2a.cpp index ac2f988..744c99e 100644 --- a/clang/test/AST/ByteCode/cxx2a.cpp +++ b/clang/test/AST/ByteCode/cxx2a.cpp @@ -225,3 +225,17 @@ namespace Dtor { static_assert(pseudo(true, false)); // both-error {{constant expression}} both-note {{in call}} static_assert(pseudo(false, true)); } + +namespace GH150705 { + struct A { }; + struct B : A { }; + struct C : A { + constexpr virtual int foo() const { return 0; } + }; + + constexpr auto p = &C::foo; + constexpr auto q = static_cast<int (A::*)() const>(p); + constexpr B b; + constexpr const A& a = b; + constexpr auto x = (a.*q)(); // both-error {{constant expression}} +} |