[clang] [clang-tools-extra] [clang-tidy] bugprone-implicit-widening ignores unsigned consts (PR #101073)

Chris Warner via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 9 09:04:11 PDT 2024


================
@@ -569,7 +573,8 @@ class Expr : public ValueStmt {
   /// Note: This does not perform the implicit conversions required by C++11
   /// [expr.const]p5.
   bool isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result = nullptr,
-                           SourceLocation *Loc = nullptr) const;
+                           SourceLocation *Loc = nullptr,
+                           bool CheckUnsignedOverflow = false) const;
----------------
cwarner-8702 wrote:

> Given that unsigned overflow is well defined and allowed in constexpr, having an argument to disallow it seems a little off.

I agree from the compiler's perspective, but it seems in-line with the purpose of a `bugprone` clang tidy check: it's a hint that something may warrant investigation to make sure it is intentional.

> From what I can tell the implementation here can just hard code the value internally to false and the public API for this function remains unchanged

I'm not seeing how, since this function sets up the `EvalInfo` that communications the option to the lower-level `CheckedIntArithmetic` function.  It's not just checking if the expression is constant, it's also calculating the result, and the overflow is detected during that calculation.

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


More information about the cfe-commits mailing list