Skip to content

Commit

Permalink
[clang][Interp] Add a failing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Apr 13, 2023
1 parent f508d9b commit 4a6a4f8
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions clang/test/AST/Interp/records.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
}

0 comments on commit 4a6a4f8

Please sign in to comment.