Skip to content

Commit

Permalink
[clang][Interp] Handle CXXNoexceptExprs
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D155707
  • Loading branch information
tbaederr committed Jul 26, 2023
1 parent 744a968 commit 378fcbf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,15 @@ bool ByteCodeExprGen<Emitter>::VisitCXXReinterpretCastExpr(
return this->emitInvalidCast(CastKind::Reinterpret, E);
}

template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitCXXNoexceptExpr(const CXXNoexceptExpr *E) {
assert(E->getType()->isBooleanType());

if (DiscardResult)
return true;
return this->emitConstBool(E->getValue(), E);
}

template <class Emitter> bool ByteCodeExprGen<Emitter>::discard(const Expr *E) {
if (E->containsErrors())
return false;
Expand Down
1 change: 1 addition & 0 deletions clang/lib/AST/Interp/ByteCodeExprGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
bool VisitPredefinedExpr(const PredefinedExpr *E);
bool VisitCXXThrowExpr(const CXXThrowExpr *E);
bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E);
bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E);

protected:
bool visitExpr(const Expr *E) override;
Expand Down
22 changes: 22 additions & 0 deletions clang/test/AST/Interp/literals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,3 +910,25 @@ namespace PredefinedExprs {
static_assert(heh(2) == 'h', "");
#endif
}

namespace NE {
constexpr int foo() noexcept {
return 1;
}
static_assert(noexcept(foo()), "");
constexpr int foo2() {
return 1;
}
static_assert(!noexcept(foo2()), "");

#if __cplusplus > 201402L
constexpr int a() {
int b = 0;
(void)noexcept(++b); // expected-warning {{expression with side effects has no effect in an unevaluated context}} \
// ref-warning {{expression with side effects has no effect in an unevaluated context}}

return b;
}
static_assert(a() == 0, "");
#endif
}
1 change: 1 addition & 0 deletions clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions -fcxx-exceptions -Wno-unevaluated-expression
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions -fcxx-exceptions -Wno-unevaluated-expression -fexperimental-new-constant-interpreter

void f(); // expected-note {{possible target for call}}
void f(int); // expected-note {{possible target for call}}
Expand Down

0 comments on commit 378fcbf

Please sign in to comment.