-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang-tidy] Rename cert-dcl58-cpp to bugprone-std-namespace-modification
#165659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
clang-tools-extra/docs/clang-tidy/checks/bugprone/dont-modify-std-namespace.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| .. title:: clang-tidy - bugprone-dont-modify-std-namespace | ||
|
|
||
| bugprone-dont-modify-std-namespace | ||
| ================================== | ||
|
|
||
| Modification of the ``std`` or ``posix`` namespace can result in undefined | ||
| behavior. | ||
| This check warns for such modifications. | ||
| The ``std`` (or ``posix``) namespace is allowed to be extended with (class or | ||
| function) template specializations that depend on an user-defined type (a type | ||
| that is not defined in the standard system headers). | ||
|
|
||
| The check detects the following (user provided) declarations in namespace ``std`` or ``posix``: | ||
|
|
||
| - Anything that is not a template specialization. | ||
| - Explicit specializations of any standard library function template or class template, if it does not have any user-defined type as template argument. | ||
| - Explicit specializations of any member function of a standard library class template. | ||
| - Explicit specializations of any member function template of a standard library class or class template. | ||
| - Explicit or partial specialization of any member class template of a standard library class or class template. | ||
|
|
||
| Examples: | ||
|
|
||
| .. code-block:: c++ | ||
|
|
||
| namespace std { | ||
| int x; // warning: modification of 'std' namespace can result in undefined behavior [bugprone-dont-modify-std-namespace] | ||
| } | ||
|
|
||
| namespace posix::a { // warning: modification of 'posix' namespace can result in undefined behavior | ||
| } | ||
|
|
||
| template <> | ||
| struct ::std::hash<long> { // warning: modification of 'std' namespace can result in undefined behavior | ||
| unsigned long operator()(const long &K) const { | ||
| return K; | ||
| } | ||
| }; | ||
|
|
||
| struct MyData { long data; }; | ||
|
|
||
| template <> | ||
| struct ::std::hash<MyData> { // no warning: specialization with user-defined type | ||
| unsigned long operator()(const MyData &K) const { | ||
| return K.data; | ||
| } | ||
| }; | ||
|
|
||
| namespace std { | ||
| template <> | ||
| void swap<bool>(bool &a, bool &b); // warning: modification of 'std' namespace can result in undefined behavior | ||
|
|
||
| template <> | ||
| bool less<void>::operator()<MyData &&, MyData &&>(MyData &&, MyData &&) const { // warning: modification of 'std' namespace can result in undefined behavior | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| References | ||
| ---------- | ||
|
|
||
| This check corresponds to the CERT C++ Coding Standard rule | ||
| `DCL58-CPP. Do not modify the standard namespaces | ||
| <https://www.securecoding.cert.org/confluence/display/cplusplus/DCL58-CPP.+Do+not+modify+the+standard+namespaces>`_. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.