diff --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp index 745a30bec33bd..a874bf3781504 100644 --- a/clang/test/AST/Interp/records.cpp +++ b/clang/test/AST/Interp/records.cpp @@ -451,3 +451,40 @@ namespace ConditionalInit { static_assert(getS(true).a == 12, ""); static_assert(getS(false).a == 13, ""); }; +/// FIXME: The following tests are broken. +/// They are using CXXDefaultInitExprs which contain a CXXThisExpr. The This pointer +/// in those refers to the declaration we are currently initializing, *not* the +/// This pointer of the current stack frame. This is something we haven't +/// implemented in the new interpreter yet. +namespace DeclRefs { + struct A{ int m; const int &f = m; }; // expected-note {{implicit use of 'this'}} + + constexpr A a{10}; // expected-error {{must be initialized by a constant expression}} + static_assert(a.m == 10, ""); + static_assert(a.f == 10, ""); // expected-error {{not an integral constant expression}} \ + // expected-note {{read of object outside its lifetime}} + + class Foo { + public: + int z = 1337; + constexpr int a() const { + A b{this->z}; + + return b.f; + } + }; + constexpr Foo f; + static_assert(f.a() == 1337, ""); + + + struct B { + A a = A{100}; + }; + constexpr B b; + /// FIXME: The following two lines don't work because we don't get the + /// pointers on the LHS correct. They make us run into an assertion + /// in CheckEvaluationResult. However, this may just be caused by the + /// problems in the previous examples. + //static_assert(b.a.m == 100, ""); + //static_assert(b.a.f == 100, ""); +}