Modify rule S6006: reword and add diff view

This commit is contained in:
Amelie Renard 2023-10-02 16:39:52 +02:00 committed by Amélie Renard
parent 6366a32909
commit c81ad8013a

View File

@ -1,9 +1,8 @@
== Why is this an issue?
``{cpp}17`` introduced ``++as_const++``: a helper function that converts a value to its corresponding const value in a succinct and more explicit way.
{cpp}17 introduced ``++as_const++``: a helper function that converts a value to its corresponding const value succinctly and more explicitly.
This is usually done to force an overloaded function call on a non-const object to resolve to the const alternative. This also can be used to instantiate a template with a const type rather than the original non-const one.
This is usually done to force an overloaded function call on a non-const object to resolve to the const alternative. Or to instantiate a template with a const type rather than the original non-const one.
This rule detects casts that can be replaced by ``++as_const++``.
@ -11,7 +10,7 @@ This rule detects casts that can be replaced by ``++as_const++``.
=== Noncompliant code example
[source,cpp]
[source,cpp,diff-id=1,diff-type=noncompliant]
----
void fn(std::vector<int>& vec);
void fn(const std::vector<int>& vec);
@ -27,7 +26,7 @@ void constFCaller() {
=== Compliant solution
[source,cpp]
[source,cpp,diff-id=1,diff-type=compliant]
----
void fn(std::vector<int>& vec);
void fn(const std::vector<int>& vec);
@ -40,3 +39,6 @@ void constFCaller() {
}
----
== Resources
* {cpp} reference - https://en.cppreference.com/w/cpp/utility/as_const[std::as_const]