gaul wrote:

Thanks for the detailed review. I've reworked this and split off the other 
forms:
- This PR now also moves `isCopyConstructible`, `isMoveConstructible`, 
`isCopyAssignable` and `isMoveAssignable` from 
cppcoreguidelines-avoid-const-or-ref-data-members into `utils::type_traits`, 
with unit tests, as a separate commit. The check uses them for the element 
requirements.
- The check now covers only the `assign` and `assign_range` rewrites. 
Initializer lists and copies, and element counts, follow as separate PRs.

The four unsafe fixes, each with a regression test:
1. The fix-it is only offered when the destination and the arguments can't 
affect each other: one side has no side effects and reads only local variables 
the other doesn't mention. `vs[i++] = std::vector<int>(i + 1, 0)` is still 
diagnosed, without a fix-it.
2. Assignments whose elements aren't copy assignable (or, for an iterator 
range, assignable from the iterator's value type) are not diagnosed.
3. The `resize` follow-up requires elements that can be moved or copied, so 
containers of immovable types like `std::mutex` aren't diagnosed.
4. The `resize` follow-up only offers `clear(); resize(n);` for an assignment 
that is directly a statement in a block, so `(v = std::vector<int>(3));` gets 
no fix-it, while `(v = std::vector<int>(3, 0));` becomes `(v.assign(3, 0));`.

CTIT: of the reports, the false positive I found is assimp's 
`PlyParser.cpp:898`, `buffer = std::vector<char>(buffer.end() - bufferSize, 
buffer.end());`, where `assign` would receive iterators into `buffer`. 
Assignments whose arguments refer into the destination are no longer diagnosed. 
The other llvm-project reports are still diagnosed, and their fix-its compile. 
`ClangFormat.cpp:472` is no longer diagnosed, because `std::string` is 
assignable from `StringRef` only through a template `operator=` the check can't 
verify. `glTFCommon.h:323` uses the assignment in a comma expression, so it 
keeps the warning without a fix-it.

The description now discloses the AI assistance.

Assisted-by: Claude Opus 5.5


https://github.com/llvm/llvm-project/pull/222159
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to