[clang] [clang-repl] Suppress [[nodiscard]] warnings for REPL printed express (PR #178661)

Vassil Vassilev via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 29 10:30:24 PST 2026


================
@@ -239,6 +239,15 @@ void DiagnoseUnused(Sema &S, const Expr *E, std::optional<unsigned> DiagID) {
   if (S.isUnevaluatedContext())
     return;
 
+  // In incremental processing mode (REPL), expressions inside TopLevelStmtDecl
+  // without a semicolon will have their values printed by the value printing
+  // mechanism. The result is therefore "used" and we should not warn about
+  // [[nodiscard]] attributes.
+  if (S.PP.isIncrementalProcessingEnabled()) {
+    if (isa<TopLevelStmtDecl>(S.CurContext))
+      return;
+  }
----------------
vgvassilev wrote:

I suspect that we should mark the expression as used when we have missing semicolon in the interpreter. Can we try that instead of having a special case here?

https://github.com/llvm/llvm-project/pull/178661


More information about the cfe-commits mailing list