[clang] [Clang][NFC] Capture by ref to avoid copying std::string (PR #138231)

Shafik Yaghmour via cfe-commits cfe-commits at lists.llvm.org
Thu May 1 22:08:44 PDT 2025


https://github.com/shafik created https://github.com/llvm/llvm-project/pull/138231

Static analysis flagged capturing BName by value as opposed to by reference. Updated capture to be by reference.

>From dc52a86f175be704bb571ce160b597a2f4011cac Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour <shafik.yaghmour at intel.com>
Date: Thu, 1 May 2025 21:56:38 -0700
Subject: [PATCH] [Clang][NFC] Capture by ref to avoid copying std::string

Static analysis flagged capturing BName by value as opposed to by reference.
Updated capture to be by reference.
---
 clang/lib/StaticAnalyzer/Core/CheckerContext.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp b/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
index d0145293fa3e5..1c4f08ae5dff5 100644
--- a/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
@@ -67,10 +67,10 @@ bool CheckerContext::isCLibraryFunction(const FunctionDecl *FD,
       //   _xxxxx_
       //   ^     ^ lookbehind and lookahead characters
 
-      const auto MatchPredecessor = [=]() -> bool {
+      const auto MatchPredecessor = [&]() -> bool {
         return start <= 0 || !llvm::isAlpha(BName[start - 1]);
       };
-      const auto MatchSuccessor = [=]() -> bool {
+      const auto MatchSuccessor = [&]() -> bool {
         std::size_t LookbehindPlace = start + Name.size();
         return LookbehindPlace >= BName.size() ||
                !llvm::isAlpha(BName[LookbehindPlace]);



More information about the cfe-commits mailing list