[clang-tools-extra] [clang-tidy] Add `modernize-use-bit-cast` check (PR #189962)

via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 19 23:03:05 PDT 2026


================
@@ -0,0 +1,279 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "UseBitCastCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/Twine.h"
+#include <cassert>
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static bool isSupportedMemcpyObjectExpr(const Expr *ExprNode) {
+  ExprNode = ExprNode->IgnoreParenImpCasts();
+
+  if (isa<DeclRefExpr>(ExprNode))
+    return true;
+
+  const auto *Member = dyn_cast<MemberExpr>(ExprNode);
+  if (!Member || !isa<FieldDecl>(Member->getMemberDecl()))
----------------
serge-sans-paille wrote:

This first `if` is odd. Why not

```
if (const auto *MemberPointer = dyn_cast<BinaryOperator>(ExprNode)) {
   ...
}
else if(const auto *Member = dyn_cast<MemberExpr>(ExprNode)) {
   ...
}
```
?

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


More information about the cfe-commits mailing list