[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() (PR #90043)

via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 25 10:16:07 PDT 2024


cor3ntin wrote:

> Please note: the guidelines do not require one to replace [] with at(), that's just one of the possible solutions. Actually at() is banned in many codebases where exceptions are banned.
> 
> It would be good to make this fix-it opt-in, configurable via option, so the check only emits a warning by default.

+1 
I find the fixit rather concerning, as it does not correspond to any widely accepted good practice. 
Using `at` does not fixes any issue, it just "shifts right" the detection of a problem.

The advices  this is trying to get at is:
 * assert in the operator[] (or use another precondition mechanism
 * Use ASan
 * use algorithms instead of loops and direct element manipulation wherever possible.


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


More information about the cfe-commits mailing list