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
10 changes: 6 additions & 4 deletions clang/lib/AST/ByteCode/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,11 @@ bool CheckRange(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
AccessKinds AK) {
if (!Ptr.isOnePastEnd())
return true;
const SourceInfo &Loc = S.Current->getSource(OpPC);
S.FFDiag(Loc, diag::note_constexpr_access_past_end)
<< AK << S.Current->getRange(OpPC);
if (S.getLangOpts().CPlusPlus) {
const SourceInfo &Loc = S.Current->getSource(OpPC);
S.FFDiag(Loc, diag::note_constexpr_access_past_end)
<< AK << S.Current->getRange(OpPC);
}
return false;
}

Expand Down Expand Up @@ -538,7 +540,7 @@ bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
return true;

if (const auto *VD = Ptr.getDeclDesc()->asVarDecl();
VD && VD->hasGlobalStorage()) {
VD && (VD->isConstexpr() || VD->hasGlobalStorage())) {
const SourceInfo &Loc = S.Current->getSource(OpPC);
if (VD->getAnyInitializer()) {
S.FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD;
Expand Down
8 changes: 8 additions & 0 deletions clang/test/AST/ByteCode/c23.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ static_assert(arg1[1] == 254);
static_assert(arg1[2] == 186);
static_assert(arg1[3] == 190);
#endif

void ghissue109095() {
constexpr char c[] = { 'a' };
constexpr int i = c[1]; // both-error {{constexpr variable 'i' must be initialized by a constant expression}}\
// both-note {{declared here}}
_Static_assert(i == c[0]); // both-error {{static assertion expression is not an integral constant expression}}\
// both-note {{initializer of 'i' is not a constant expression}}
}
9 changes: 9 additions & 0 deletions clang/test/AST/ByteCode/literals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,3 +1315,12 @@ namespace {
}
}
#endif

void localConstexpr() {
constexpr int a = 1/0; // both-error {{must be initialized by a constant expression}} \
// both-note {{division by zero}} \
// both-warning {{division by zero is undefined}} \
// both-note {{declared here}}
static_assert(a == 0, ""); // both-error {{not an integral constant expression}} \
// both-note {{initializer of 'a' is not a constant expression}}
}
Loading