[clang] [Clang][NFC] Introduce no local variable to avoid use after move (PR #139784)
Shafik Yaghmour via cfe-commits
cfe-commits at lists.llvm.org
Tue May 13 12:52:14 PDT 2025
https://github.com/shafik created https://github.com/llvm/llvm-project/pull/139784
Static analysis flagged the use of Left.size() because we just moved out of Left and that would be undefined behavior. Fix is to take the size and store it in a local variable instead.
>From df92525e63ff7c8953c7a3a0d191c01397d27dda Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour <shafik.yaghmour at intel.com>
Date: Tue, 13 May 2025 12:49:55 -0700
Subject: [PATCH] [Clang][NFC] Introduce no local variable to avoid use after
move
Static analysis flagged the use of Left.size() because we just moved out of Left
and that would be undefined behavior. Fix is to take the size and store it in a
local variable instead.
---
clang/lib/Sema/SemaConcept.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 15b9c97489e7f..543bd450c554e 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1999,8 +1999,9 @@ FormulaType SubsumptionChecker::Normalize(const NormalizedConstraint &NC) {
});
if (NC.getCompoundKind() == FormulaType::Kind) {
+ auto SizeLeft = Left.size();
Res = std::move(Left);
- Res.reserve(Left.size() + Right.size());
+ Res.reserve(SizeLeft + Right.size());
std::for_each(std::make_move_iterator(Right.begin()),
std::make_move_iterator(Right.end()), Add);
return Res;
More information about the cfe-commits
mailing list