[clang] [Clang] [Sema] Document invariant in Sema::AddOverloadCandidate (PR #135256)

via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 10 13:56:23 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Shafik Yaghmour (shafik)

<details>
<summary>Changes</summary>

Static analysis flagged 1 - ArgIdx in Sema::AddOverloadCandidate for its potential to overflow.

Turns out this is intentional since when PO ==
OverloadCandidateParamOrder::Reversed Args.size() is always two, so this will never overflow.

We document using an assert.

Fixes: https://github.com/llvm/llvm-project/issues/135086

---
Full diff: https://github.com/llvm/llvm-project/pull/135256.diff


1 Files Affected:

- (modified) clang/lib/Sema/SemaOverload.cpp (+1) 


``````````diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index f46ef2c7f5bd6..9c2df0b21d278 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7189,6 +7189,7 @@ void Sema::AddOverloadCandidate(
     }
   }
 
+  assert(PO != OverloadCandidateParamOrder::Reversed || Args.size() == 2);
   // Determine the implicit conversion sequences for each of the
   // arguments.
   for (unsigned ArgIdx = 0; ArgIdx < Args.size(); ++ArgIdx) {

``````````

</details>


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


More information about the cfe-commits mailing list