================ @@ -3,15 +3,35 @@ readability-container-data-pointer ================================== -Finds cases where code could use ``data()`` rather than the address of the -element at index 0 in a container. This pattern is commonly used to materialize -a pointer to the backing data of a container. ``std::vector`` and +Finds cases where code could use ``data()`` or ``c_str()`` rather than the +address of the element at index 0 in a container. This pattern is commonly used +to materialize a pointer to the backing data of a container. ``std::vector`` and ``std::string`` provide a ``data()`` accessor to retrieve the data pointer which should be preferred. +This check suggests ``data()`` for non-const pointer contexts and ``c_str()`` +for const pointer contexts when available. This provides better semantic +clarity: ``c_str()`` explicitly indicates read-only access to string data, +while ``data()`` may allow modifications. ---------------- vbvictor wrote:
We should also add support (if not already) to use data() on const objects as well (when we have proper overload of data()) https://github.com/llvm/llvm-project/pull/190590 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
