Skip to content

Commit c80e026

Browse files
Add related rules
1 parent 6db088b commit c80e026

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

rules/S8216/cfamily/rule.adoc

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Relying on features that are not part of the configured {cpp} standard leads to
88
* Uses of features removed in the configured {cpp} standard.
99
* Uses of C-only constructs that some {cpp} implementations accept as extensions.
1010

11-
Keeping code within the configured standard ensures consistency across compilers and prevents accidental lock-in to permissive extensions.
11+
Keeping code within the configured standard ensures consistency across compilers and prevents accidental lock-in to permissive extensions. Check the list of related rules for focused rules that report specific compiler extension cases; S8216 covers remaining standard violations not addressed by these specialized rules.
1212

1313
== How to fix it
1414

@@ -88,24 +88,34 @@ int values[3] = {};
8888
values[1] = 5;
8989
----
9090

91-
=== Removed library feature
91+
=== std::bind1st and std::bind2nd
9292

93-
Some features are removed in newer standards. For example, ``++std::auto_ptr++`` was removed in {cpp}17; using it when the configured standard has removed it is noncompliant.
93+
The ``++std::bind1st++`` and ``++std::bind2nd++`` function templates were deprecated in {cpp}11 and removed in {cpp}17. When the configured standard is {cpp}17 or later, using these functions is noncompliant. Under earlier standards, the same code may be compliant but is still deprecated.
9494

9595
==== Noncompliant code example
9696
[source,cpp,diff-id=5,diff-type=noncompliant]
9797
----
98-
#include <memory>
98+
#include <functional>
9999
100-
std::auto_ptr<int> p(new int(42)); // Noncompliant in C++17 and later
100+
auto bound = std::bind1st(std::greater<int>(), 5); // Noncompliant in C++17 or later
101+
auto result = bound(3); // Returns true (5 > 3)
101102
----
102103

103104
==== Compliant solution
104105
[source,cpp,diff-id=5,diff-type=compliant]
105106
----
106-
#include <memory>
107+
#include <functional>
107108
108-
std::unique_ptr<int> p = std::make_unique<int>(42);
109+
auto bound = std::bind(std::greater<int>(), 5, std::placeholders::_1);
110+
auto result = bound(3); // Returns true (5 > 3)
111+
----
112+
113+
Or use a lambda expression:
114+
115+
[source,cpp,diff-id=5,diff-type=compliant]
116+
----
117+
auto bound = [](int x) { return std::greater<int>()(5, x); };
118+
auto result = bound(3); // Returns true (5 > 3)
109119
----
110120

111121
=== Limitations
@@ -119,3 +129,14 @@ This version primarily reports extensions starting from {cpp}20 and later. For e
119129
* S3715 - GNU extensions should not be used
120130
* S8230 - MSVC-specific extensions should not be used
121131
* S8231 - Non-standard attributes should not be used
132+
* S3731 - Reports usages of ``++auto++`` as a storage class specifier, which was removed in {cpp}11
133+
* S7129 - Reports assignments of string literals to mutable char pointers, which is allowed only before {cpp}11
134+
* S6172 - Reports non-standard usages of C++20 designated initializers
135+
* S2754 - Reports empty declarations, which are not allowed by the standard
136+
* S796 - Detects usages of non-standard escape sequences
137+
* S3689 - Detects duplicate declaration specifiers
138+
* S2324 - Reports flexible array members, which are not part of the C++ standard
139+
* S4997 - Reports usages of ``++std::auto_ptr++``, which was removed in {cpp}17
140+
* S2668 - Reports usages of the increment operator on a ``++bool++`` variable, which was removed in {cpp}17
141+
* S3522 - Reports usages of the ``++register++`` storage class specifier, which was removed in {cpp}17
142+
* S5020 - Reports usages of ``++random_shuffle++``, which was removed in {cpp}17

0 commit comments

Comments
 (0)