diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index d2995fb57d8be..c7c87d966cbe7 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2004,6 +2004,9 @@ bool ByteCodeExprGen::VisitUnaryOperator(const UnaryOperator *E) { case UO_Real: // __real x case UO_Imag: // __imag x case UO_Extension: + if (DiscardResult) + return this->discard(SubExpr); + return this->visit(SubExpr); case UO_Coawait: assert(false && "Unhandled opcode"); } diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp index 5df7b7e5e6e8b..f0513810eb4b7 100644 --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -880,5 +880,16 @@ namespace PredefinedExprs { static_assert(strings_match(__func__, "foo"), ""); static_assert(strings_match(__PRETTY_FUNCTION__, "void PredefinedExprs::foo()"), ""); } + + constexpr char heh(unsigned index) { + __FUNCTION__; // ref-warning {{result unused}} \ + // expected-warning {{result unused}} + __extension__ __FUNCTION__; // ref-warning {{result unused}} \ + // expected-warning {{result unused}} + return __FUNCTION__[index]; + } + static_assert(heh(0) == 'h', ""); + static_assert(heh(1) == 'e', ""); + static_assert(heh(2) == 'h', ""); #endif }