Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/lib/AST/ByteCode/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,8 @@ bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T) {
// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1677
// Therefore, we use the C++1y behavior.

if (S.Current->getFunction() && S.Current->getFunction()->isConstructor() &&
if (!S.Current->isBottomFrame() &&
S.Current->getFunction()->isConstructor() &&
S.Current->getThis().getDeclDesc()->asDecl() == S.EvaluatingDecl) {
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/AST/ByteCode/InterpFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ class InterpFrame final : public Frame {
/// Returns the 'this' pointer.
const Pointer &getThis() const {
assert(hasThisPointer());
assert(!isBottomFrame());
return stackRef<Pointer>(ThisPointerOffset);
}

/// Returns the RVO pointer, if the Function has one.
const Pointer &getRVOPtr() const {
assert(Func);
assert(Func->hasRVO());
assert(!isBottomFrame());
return stackRef<Pointer>(0);
}

Expand Down
12 changes: 12 additions & 0 deletions clang/test/AST/ByteCode/new-delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,18 @@ namespace ZeroSizeArray {
static_assert(foo() == 0);
}

namespace NonLiteralType {
/// This used to crash.
constexpr void foo() {
struct O {};

struct S {
O *s;
constexpr S() : s{std::allocator<O>{}.allocate(1)} {}
};
}
}

#else
/// Make sure we reject this prior to C++20
constexpr int a() { // both-error {{never produces a constant expression}}
Expand Down
Loading