================ @@ -222,17 +222,17 @@ static bool DiagnoseNoDiscard(Sema &S, const WarnUnusedResultAttr *A, return S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2; } -void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) { - if (const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S)) - return DiagnoseUnusedExprResult(Label->getSubStmt(), DiagID); - - const Expr *E = dyn_cast_or_null<Expr>(S); - if (!E) - return; +static void DiagnoseUnused(Sema &S, const Expr *E, + std::optional<unsigned> DiagID) { + // When called from Sema::DiagnoseUnusedExprResult, DiagID is a diagnostic for + // where this expression is not used. When called from + // Sema::DiagnoseDiscardedNodiscard, DiagID is std::nullopt and this function + // will only diagnose [[nodiscard]], [[gnu::warn_unused_result]] and similar ---------------- cor3ntin wrote:
```suggestion // Diagnoses unused expressions that call functions marked [[nodiscard]], [[gnu::warn_unused_result]] and similar. Additionally, a DiagID can be provided to emit a warning in additional contexts (such as for an unused LHS of a comma expression) ``` https://github.com/llvm/llvm-project/pull/95112 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits