Modify rule S6010: add diff view and add documentation link

This commit is contained in:
Amelie Renard 2023-10-02 16:53:03 +02:00 committed by Amélie Renard
parent 54626a31b9
commit 258f2055da

View File

@ -1,18 +1,18 @@
== Why is this an issue?
Since {cpp}17, the class ``++std::filesystem::path++`` can be used to store a file path. Compared to a regular string, it offers several advantages:
Introduced in {cpp}17, the class ``++std::filesystem::path++`` can store a file path. Compared to a regular string, it offers several advantages:
* Having a dedicated type makes the intention clear
* This class stores the path with an encoding that is appropriate to the OS where the program runs
* It provides several functions that make it more convenient to manipulate than a ``++string++`` (for instance ``++operator/++`` for concatenations)
* It provides several functions that make it more convenient to manipulate than a ``++string++`` (for instance, ``++operator/++`` for concatenations)
* It provides a normalized way to specify the path, easing the portability of the code (on Windows and Linux, the native way is equivalent to the normalized way, which reduces overhead).
This rule raises an issue when the same ``++string++`` is converted several times to a ``++path++`` because it indicates that a single path object could have been used in all occurrences. Additionally, it can also be more efficient, since a conversion from ``++string++`` to ``++path++`` may require a change of encoding and a memory allocation.
This rule raises an issue when the same ``++string++`` is converted several times to a ``++path++`` because it indicates that a single path object could have been used in all occurrences. It can also be more efficient since conversion from ``++string++`` to ``++path++`` may require a change of encoding and memory allocation.
=== Noncompliant code example
[source,cpp]
[source,cpp,diff-id=1,diff-type=noncompliant]
----
std::string getUserData();
namespace fs = std::filesystem;
@ -27,7 +27,7 @@ void f() {
=== Compliant solution
[source,cpp]
[source,cpp,diff-id=1,diff-type=compliant]
----
std::string getUserData();
namespace fs = std::filesystem;
@ -39,3 +39,7 @@ void f() {
}
----
== Resources
* {cpp} reference - https://en.cppreference.com/w/cpp/filesystem/path[std::filesystem::path]