================ @@ -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:
UPD: It can already handle const: https://godbolt.org/z/31YK9K9z9. So I'm strongly for making this change into an option (off by default). https://github.com/llvm/llvm-project/pull/190590 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
