1 .. title:: clang-tidy - cert-dcl58-cpp
6 Modification of the ``std`` or ``posix`` namespace can result in undefined
8 This check warns for such modifications.
9 The ``std`` (or ``posix``) namespace is allowed to be extended with (class or
10 function) template specializations that depend on an user-defined type (a type
11 that is not defined in the standard system headers).
13 The check detects the following (user provided) declarations in namespace ``std`` or ``posix``:
15 - Anything that is not a template specialization.
16 - Explicit specializations of any standard library function template or class template, if it does not have any user-defined type as template argument.
17 - Explicit specializations of any member function of a standard library class template.
18 - Explicit specializations of any member function template of a standard library class or class template.
19 - Explicit or partial specialization of any member class template of a standard library class or class template.
26 int x; // warning: modification of 'std' namespace can result in undefined behavior [cert-dcl58-cpp]
29 namespace posix::a { // warning: modification of 'posix' namespace can result in undefined behavior
33 struct ::std::hash<long> { // warning: modification of 'std' namespace can result in undefined behavior
34 unsigned long operator()(const long &K) const {
39 struct MyData { long data; };
42 struct ::std::hash<MyData> { // no warning: specialization with user-defined type
43 unsigned long operator()(const MyData &K) const {
50 void swap<bool>(bool &a, bool &b); // warning: modification of 'std' namespace can result in undefined behavior
53 bool less<void>::operator()<MyData &&, MyData &&>(MyData &&, MyData &&) const { // warning: modification of 'std' namespace can result in undefined behavior
58 This check corresponds to the CERT C++ Coding Standard rule
59 `DCL58-CPP. Do not modify the standard namespaces
60 <https://www.securecoding.cert.org/confluence/display/cplusplus/DCL58-CPP.+Do+not+modify+the+standard+namespaces>`_.