[clang] [clang-repl] Suppress [[nodiscard]] warnings for REPL printed express (PR #178661)
Vassil Vassilev via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 26 08:02:35 PST 2026
================
@@ -469,11 +470,31 @@ Interpreter::Parse(llvm::StringRef Code) {
// printing could cause it.
getCompilerInstance()->getDiagnostics().setSeverity(
clang::diag::warn_unused_expr, diag::Severity::Ignored, SourceLocation());
+ // Suppress [[nodiscard]] warnings during parsing since we don't know yet
+ // if the expression has a missing semicolon (value printed) or not.
+ // If the value is printed, it's considered "used" so no warning is needed.
+ getCompilerInstance()->getDiagnostics().setSeverity(
+ clang::diag::warn_unused_result, diag::Severity::Ignored,
+ SourceLocation());
llvm::Expected<TranslationUnitDecl *> TuOrErr = IncrParser->Parse(Code);
if (!TuOrErr)
return TuOrErr.takeError();
+ // After parsing, re-enable [[nodiscard]] warnings and diagnose for
----------------
vgvassilev wrote:
Can we trace what happens in clang when a declaration is used? The node must be marked somehow so that the diagnostics don’t report it. It’d be probably better to do the same for these expressions rather than suppressing the diagnostics.
https://github.com/llvm/llvm-project/pull/178661
More information about the cfe-commits
mailing list