Skip to content

Commit

Permalink
[clang][Interp] Don't assume throw stmts have a subexpr
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D156503
  • Loading branch information
tbaederr committed Jul 28, 2023
1 parent 81fb216 commit 7010a4f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ bool ByteCodeExprGen<Emitter>::VisitPredefinedExpr(const PredefinedExpr *E) {

template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitCXXThrowExpr(const CXXThrowExpr *E) {
if (!this->discard(E->getSubExpr()))
if (E->getSubExpr() && !this->discard(E->getSubExpr()))
return false;

return this->emitInvalid(E);
Expand Down
11 changes: 11 additions & 0 deletions clang/test/AST/Interp/invalid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ namespace Throw {
// ref-note {{subexpression not valid in a constant expression}}
return 0;
}

constexpr int NoSubExpr() { // ref-error {{never produces a constant expression}} \
// expected-error {{never produces a constant expression}}
throw; // ref-note 2{{subexpression not valid}} \
// expected-note 2{{subexpression not valid}}
return 0;
}
static_assert(NoSubExpr() == 0, ""); // ref-error {{not an integral constant expression}} \
// ref-note {{in call to}} \
// expected-error {{not an integral constant expression}} \
// expected-note {{in call to}}
}

namespace Asm {
Expand Down

0 comments on commit 7010a4f

Please sign in to comment.