[PATCH] D155064: [clang][SemaCXX] Diagnose tautological uses of consteval if and is_constant_evaluated

Corentin Jabot via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 19 07:51:05 PDT 2023


cor3ntin added a comment.

This looks good to me modulo nitpicks. 
When you land that, please make an issue on github for the missing narrowing warning, it seems important.

I'll wait before approving in case @aaron.ballman spot things i missed



================
Comment at: clang/lib/Sema/SemaExpr.cpp:7089
       DiagnosedUnqualifiedCallsToStdFunctions(*this, CE);
+      DiagnoseTautologicalIsConstantEvaluated(*this, CE);
+    }
----------------
I think `DiagnoseTautologicalIsConstantEvaluated` might be confusing without context, suggesting another name


================
Comment at: clang/lib/Sema/SemaStmt.cpp:938-944
+    bool AlwaysFalse = ExprEvalContexts.back().IsRuntimeEvaluated;
+    if (AlwaysTrue)
+      Diags.Report(IfLoc, diag::warn_tautological_consteval_if)
+          << (StatementKind == IfStatementKind::ConstevalNegated);
+    else if (AlwaysFalse)
+      Diags.Report(IfLoc, diag::warn_tautological_consteval_if)
+          << (StatementKind == IfStatementKind::ConstevalNonNegated);
----------------
I think that might be somewhat nicer (make sure to run clang-format :))


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155064/new/

https://reviews.llvm.org/D155064



More information about the cfe-commits mailing list