diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -188,7 +188,12 @@ template bool ByteCodeExprGen::VisitParenExpr(const ParenExpr *PE) { - return this->visit(PE->getSubExpr()); + const Expr *SubExpr = PE->getSubExpr(); + + if (DiscardResult) + return this->discard(SubExpr); + + return this->visit(SubExpr); } template @@ -1872,6 +1877,9 @@ template bool ByteCodeExprGen::VisitDeclRefExpr(const DeclRefExpr *E) { + if (DiscardResult) + return true; + const auto *D = E->getDecl(); if (const auto *ECD = dyn_cast(D)) { diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -814,4 +814,18 @@ return F{12}.a; } static_assert(ignoredDecls() == 12, ""); + +struct A{}; +constexpr int ignoredExprs() { + (void)(1 / 2); + A a; + a; // expected-warning {{unused}} \ + // ref-warning {{unused}} + (void)a; + (a); // expected-warning {{unused}} \ + // ref-warning {{unused}} + + return 0; +} + #endif