[clang-tools-extra] [clang-tidy] Rename `cert-dcl58-cpp` to `bugprone-std-namespace-modification` (PR #165659)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 2 18:14:25 PST 2025
https://github.com/zeyi2 updated https://github.com/llvm/llvm-project/pull/165659
>From 0f42a4416fbc86556d45df83fbbe269253b6eb8b Mon Sep 17 00:00:00 2001
From: mtx <mitchell.xu2 at gmail.com>
Date: Thu, 30 Oct 2025 13:12:26 +0800
Subject: [PATCH 1/4] [clang-tidy] Rename `cert-dcl58-cpp` to
`bugprone-dont-modify-std-namespace`
---
.../bugprone/BugproneTidyModule.cpp | 3 +
.../clang-tidy/bugprone/CMakeLists.txt | 1 +
.../DontModifyStdNamespaceCheck.cpp | 6 +-
.../DontModifyStdNamespaceCheck.h | 12 ++--
.../clang-tidy/cert/CERTTidyModule.cpp | 5 +-
.../clang-tidy/cert/CMakeLists.txt | 1 -
clang-tools-extra/docs/ReleaseNotes.rst | 7 ++-
.../bugprone/dont-modify-std-namespace.rst | 63 +++++++++++++++++++
.../docs/clang-tidy/checks/cert/dcl58-cpp.rst | 54 +---------------
.../docs/clang-tidy/checks/list.rst | 3 +-
.../Inputs/Headers/system-header-simulation.h | 2 +-
.../dont-modify-std-namespace.cpp} | 4 +-
12 files changed, 93 insertions(+), 68 deletions(-)
rename clang-tools-extra/clang-tidy/{cert => bugprone}/DontModifyStdNamespaceCheck.cpp (97%)
rename clang-tools-extra/clang-tidy/{cert => bugprone}/DontModifyStdNamespaceCheck.h (71%)
create mode 100644 clang-tools-extra/docs/clang-tidy/checks/bugprone/dont-modify-std-namespace.rst
rename clang-tools-extra/test/clang-tidy/checkers/{cert/dcl58-cpp.cpp => bugprone/dont-modify-std-namespace.cpp} (97%)
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index e6115f67656bc..6f30e4e232c81 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -25,6 +25,7 @@
#include "CrtpConstructorAccessibilityCheck.h"
#include "DanglingHandleCheck.h"
#include "DerivedMethodShadowingBaseMethodCheck.h"
+#include "DontModifyStdNamespaceCheck.h"
#include "DynamicStaticInitializersCheck.h"
#include "EasilySwappableParametersCheck.h"
#include "EmptyCatchCheck.h"
@@ -141,6 +142,8 @@ class BugproneModule : public ClangTidyModule {
"bugprone-dangling-handle");
CheckFactories.registerCheck<DerivedMethodShadowingBaseMethodCheck>(
"bugprone-derived-method-shadowing-base-method");
+ CheckFactories.registerCheck<DontModifyStdNamespaceCheck>(
+ "bugprone-dont-modify-std-namespace");
CheckFactories.registerCheck<DynamicStaticInitializersCheck>(
"bugprone-dynamic-static-initializers");
CheckFactories.registerCheck<EasilySwappableParametersCheck>(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index c8943e5b22ef8..358a73f36c9e6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -21,6 +21,7 @@ add_clang_library(clangTidyBugproneModule STATIC
CrtpConstructorAccessibilityCheck.cpp
DanglingHandleCheck.cpp
DerivedMethodShadowingBaseMethodCheck.cpp
+ DontModifyStdNamespaceCheck.cpp
DynamicStaticInitializersCheck.cpp
EasilySwappableParametersCheck.cpp
EmptyCatchCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DontModifyStdNamespaceCheck.cpp
similarity index 97%
rename from clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp
rename to clang-tools-extra/clang-tidy/bugprone/DontModifyStdNamespaceCheck.cpp
index 79fbc66b5f8a3..869120a9a0864 100644
--- a/clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DontModifyStdNamespaceCheck.cpp
@@ -36,7 +36,7 @@ AST_POLYMORPHIC_MATCHER_P(
} // namespace
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
void DontModifyStdNamespaceCheck::registerMatchers(MatchFinder *Finder) {
auto HasStdParent =
@@ -96,7 +96,7 @@ void DontModifyStdNamespaceCheck::registerMatchers(MatchFinder *Finder) {
.bind("decl"),
this);
}
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
static const NamespaceDecl *getTopLevelLexicalNamespaceDecl(const Decl *D) {
const NamespaceDecl *LastNS = nullptr;
@@ -108,7 +108,7 @@ static const NamespaceDecl *getTopLevelLexicalNamespaceDecl(const Decl *D) {
return LastNS;
}
-void clang::tidy::cert::DontModifyStdNamespaceCheck::check(
+void clang::tidy::bugprone::DontModifyStdNamespaceCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *D = Result.Nodes.getNodeAs<Decl>("decl");
const auto *NS = Result.Nodes.getNodeAs<NamespaceDecl>("nmspc");
diff --git a/clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.h b/clang-tools-extra/clang-tidy/bugprone/DontModifyStdNamespaceCheck.h
similarity index 71%
rename from clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.h
rename to clang-tools-extra/clang-tidy/bugprone/DontModifyStdNamespaceCheck.h
index cfcd878644ddb..eb8125f4092d2 100644
--- a/clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/DontModifyStdNamespaceCheck.h
@@ -6,18 +6,18 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_DONT_MODIFY_STD_NAMESPACE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_DONT_MODIFY_STD_NAMESPACE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DONT_MODIFY_STD_NAMESPACE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DONT_MODIFY_STD_NAMESPACE_H
#include "../ClangTidyCheck.h"
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
/// Modification of the std or posix namespace can result in undefined behavior.
/// This check warns for such modifications.
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/cert/dcl58-cpp.html
+/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/dont-modify-std-namespace.html
class DontModifyStdNamespaceCheck : public ClangTidyCheck {
public:
DontModifyStdNamespaceCheck(StringRef Name, ClangTidyContext *Context)
@@ -29,6 +29,6 @@ class DontModifyStdNamespaceCheck : public ClangTidyCheck {
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_DONT_MODIFY_STD_NAMESPACE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DONT_MODIFY_STD_NAMESPACE_H
diff --git a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
index c1ca2cec7a1eb..cdd3a8b54f99b 100644
--- a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
@@ -11,6 +11,7 @@
#include "../ClangTidyModuleRegistry.h"
#include "../bugprone/BadSignalToKillThreadCheck.h"
#include "../bugprone/CommandProcessorCheck.h"
+#include "../bugprone/DontModifyStdNamespaceCheck.h"
#include "../bugprone/PointerArithmeticOnPolymorphicObjectCheck.h"
#include "../bugprone/ReservedIdentifierCheck.h"
#include "../bugprone/SignalHandlerCheck.h"
@@ -35,7 +36,6 @@
#include "../readability/EnumInitialValueCheck.h"
#include "../readability/UppercaseLiteralSuffixCheck.h"
#include "DefaultOperatorNewAlignmentCheck.h"
-#include "DontModifyStdNamespaceCheck.h"
#include "FloatLoopCounter.h"
#include "LimitedRandomnessCheck.h"
#include "MutatingCopyCheck.h"
@@ -251,7 +251,8 @@ class CERTModule : public ClangTidyModule {
"cert-dcl51-cpp");
CheckFactories.registerCheck<misc::NewDeleteOverloadsCheck>(
"cert-dcl54-cpp");
- CheckFactories.registerCheck<DontModifyStdNamespaceCheck>("cert-dcl58-cpp");
+ CheckFactories.registerCheck<bugprone::DontModifyStdNamespaceCheck>(
+ "cert-dcl58-cpp");
CheckFactories.registerCheck<google::build::UnnamedNamespaceInHeaderCheck>(
"cert-dcl59-cpp");
// ERR
diff --git a/clang-tools-extra/clang-tidy/cert/CMakeLists.txt b/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
index 453d1d30921e9..33965a3d236c8 100644
--- a/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/cert/CMakeLists.txt
@@ -6,7 +6,6 @@ set(LLVM_LINK_COMPONENTS
add_clang_library(clangTidyCERTModule STATIC
CERTTidyModule.cpp
DefaultOperatorNewAlignmentCheck.cpp
- DontModifyStdNamespaceCheck.cpp
FloatLoopCounter.cpp
LimitedRandomnessCheck.cpp
MutatingCopyCheck.cpp
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 6701bf25df166..d1702bb9286de 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -244,6 +244,11 @@ New check aliases
<clang-tidy/checks/modernize/avoid-variadic-functions>`
keeping initial check as an alias to the new one.
+- Renamed :doc:`cert-dcl58-cpp <clang-tidy/checks/cert/dcl58-cpp>` to
+ :doc:`bugprone-dont-modify-std-namespace
+ <clang-tidy/checks/bugprone/dont-modify-std-namespace>`
+ keeping initial check as an alias to the new one.
+
- Renamed :doc:`cert-env33-c <clang-tidy/checks/cert/env33-c>` to
:doc:`bugprone-command-processor
<clang-tidy/checks/bugprone/command-processor>`
@@ -367,7 +372,7 @@ Changes in existing checks
- Improved :doc:`misc-const-correctness
<clang-tidy/checks/misc/const-correctness>` check to avoid false
- positives when pointers is transferred to non-const references
+ positives when pointers is transferred to non-const references
and avoid false positives of function pointer and fix false
positives on return of non-const pointer.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/dont-modify-std-namespace.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/dont-modify-std-namespace.rst
new file mode 100644
index 0000000000000..9293fa0a42763
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/dont-modify-std-namespace.rst
@@ -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>`_.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/dcl58-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/dcl58-cpp.rst
index fbcc6281a8898..ed2e4ec383c2e 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/dcl58-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/dcl58-cpp.rst
@@ -3,57 +3,9 @@
cert-dcl58-cpp
==============
-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 [cert-dcl58-cpp]
- }
-
- 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;
- }
- }
+The `cert-dcl58-cpp` is an aliaes, please see
+`bugprone-dont-modify-std-namespace <../bugprone/dont-modify-std-namespace.html>`_
+for more information.
This check corresponds to the CERT C++ Coding Standard rule
`DCL58-CPP. Do not modify the standard namespaces
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index d3c89e469188d..27d444351c70f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -93,6 +93,7 @@ Clang-Tidy Checks
:doc:`bugprone-crtp-constructor-accessibility <bugprone/crtp-constructor-accessibility>`, "Yes"
:doc:`bugprone-dangling-handle <bugprone/dangling-handle>`,
:doc:`bugprone-derived-method-shadowing-base-method <bugprone/derived-method-shadowing-base-method>`,
+ :doc:`bugprone-dont-modify-std-namespace <bugprone/dont-modify-std-namespace>`,
:doc:`bugprone-dynamic-static-initializers <bugprone/dynamic-static-initializers>`,
:doc:`bugprone-easily-swappable-parameters <bugprone/easily-swappable-parameters>`,
:doc:`bugprone-empty-catch <bugprone/empty-catch>`,
@@ -173,7 +174,6 @@ Clang-Tidy Checks
:doc:`bugprone-unused-return-value <bugprone/unused-return-value>`,
:doc:`bugprone-use-after-move <bugprone/use-after-move>`,
:doc:`bugprone-virtual-near-miss <bugprone/virtual-near-miss>`, "Yes"
- :doc:`cert-dcl58-cpp <cert/dcl58-cpp>`,
:doc:`cert-err33-c <cert/err33-c>`,
:doc:`cert-err60-cpp <cert/err60-cpp>`,
:doc:`cert-flp30-c <cert/flp30-c>`,
@@ -441,6 +441,7 @@ Check aliases
:doc:`cert-dcl50-cpp <cert/dcl50-cpp>`, :doc:`modernize-avoid-variadic-functions <modernize/avoid-variadic-functions>`,
:doc:`cert-dcl51-cpp <cert/dcl51-cpp>`, :doc:`bugprone-reserved-identifier <bugprone/reserved-identifier>`, "Yes"
:doc:`cert-dcl54-cpp <cert/dcl54-cpp>`, :doc:`misc-new-delete-overloads <misc/new-delete-overloads>`,
+ :docs:`cert-dcl58-cpp <cert/dcl58-cpp>`, :doc:`bugprone-dont-modify-std-namespace <bugprone/dont-modify-std-namespace>`,
:doc:`cert-dcl59-cpp <cert/dcl59-cpp>`, :doc:`google-build-namespaces <google/build-namespaces>`,
:doc:`cert-err09-cpp <cert/err09-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
:doc:`cert-env33-c <cert/env33-c>`, :doc:`bugprone-command-processor <bugprone/command-processor>`,
diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-header-simulation.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-header-simulation.h
index b6977cd9ce6c6..2c4293dafb3e2 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-header-simulation.h
+++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-header-simulation.h
@@ -59,7 +59,7 @@ struct X {};
} // namespace std
// Template specializations that are in a system-header file.
-// The purpose is to test cert-dcl58-cpp (no warnings here).
+// The purpose is to test bugprone-dont-modify-std-namespace (no warnings here).
namespace std {
template <>
void swap<short>(short &, short &){};
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cert/dcl58-cpp.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/dont-modify-std-namespace.cpp
similarity index 97%
rename from clang-tools-extra/test/clang-tidy/checkers/cert/dcl58-cpp.cpp
rename to clang-tools-extra/test/clang-tidy/checkers/bugprone/dont-modify-std-namespace.cpp
index 01964e7dc6c76..a53ba37d5ac95 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cert/dcl58-cpp.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/dont-modify-std-namespace.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++17-or-later %s cert-dcl58-cpp %t -- -- -I %clang_tidy_headers
+// RUN: %check_clang_tidy -std=c++17-or-later %s bugprone-dont-modify-std-namespace %t -- -- -I %clang_tidy_headers
#include "system-header-simulation.h"
@@ -15,7 +15,7 @@ namespace A {
}
namespace posix {
-// CHECK-MESSAGES: :[[@LINE+2]]:11: warning: modification of 'posix' namespace can result in undefined behavior [cert-dcl58-cpp]
+// CHECK-MESSAGES: :[[@LINE+2]]:11: warning: modification of 'posix' namespace can result in undefined behavior [bugprone-dont-modify-std-namespace]
// CHECK-MESSAGES: :[[@LINE-2]]:11: note: 'posix' namespace opened here
namespace foo {
int foobar;
>From e41ba1ce1fa4fe57a7305947feda71a0320e67c8 Mon Sep 17 00:00:00 2001
From: mtx <mitchell.xu2 at gmail.com>
Date: Thu, 30 Oct 2025 14:49:47 +0800
Subject: [PATCH 2/4] fix format
---
.../clang-tidy/bugprone/DontModifyStdNamespaceCheck.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/bugprone/DontModifyStdNamespaceCheck.h b/clang-tools-extra/clang-tidy/bugprone/DontModifyStdNamespaceCheck.h
index eb8125f4092d2..751b2fd98c87b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DontModifyStdNamespaceCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/DontModifyStdNamespaceCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DONT_MODIFY_STD_NAMESPACE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DONT_MODIFY_STD_NAMESPACE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DONTMODIFYSTDNAMESPACECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DONTMODIFYSTDNAMESPACECHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ class DontModifyStdNamespaceCheck : public ClangTidyCheck {
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DONT_MODIFY_STD_NAMESPACE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DONTMODIFYSTDNAMESPACECHECK_H
>From 6d1057400f2ff8b6848aee7ae8add080d33bc912 Mon Sep 17 00:00:00 2001
From: mtx <mitchell.xu2 at gmail.com>
Date: Thu, 30 Oct 2025 14:57:18 +0800
Subject: [PATCH 3/4] fix docs
---
clang-tools-extra/docs/clang-tidy/checks/list.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 27d444351c70f..056ed07516fb1 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -441,7 +441,7 @@ Check aliases
:doc:`cert-dcl50-cpp <cert/dcl50-cpp>`, :doc:`modernize-avoid-variadic-functions <modernize/avoid-variadic-functions>`,
:doc:`cert-dcl51-cpp <cert/dcl51-cpp>`, :doc:`bugprone-reserved-identifier <bugprone/reserved-identifier>`, "Yes"
:doc:`cert-dcl54-cpp <cert/dcl54-cpp>`, :doc:`misc-new-delete-overloads <misc/new-delete-overloads>`,
- :docs:`cert-dcl58-cpp <cert/dcl58-cpp>`, :doc:`bugprone-dont-modify-std-namespace <bugprone/dont-modify-std-namespace>`,
+ :doc:`cert-dcl58-cpp <cert/dcl58-cpp>`, :doc:`bugprone-dont-modify-std-namespace <bugprone/dont-modify-std-namespace>`,
:doc:`cert-dcl59-cpp <cert/dcl59-cpp>`, :doc:`google-build-namespaces <google/build-namespaces>`,
:doc:`cert-err09-cpp <cert/err09-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
:doc:`cert-env33-c <cert/env33-c>`, :doc:`bugprone-command-processor <bugprone/command-processor>`,
>From 677ff04961ac95605898bb042d2455b9c406b0cb Mon Sep 17 00:00:00 2001
From: mtx <mitchell.xu2 at gmail.com>
Date: Mon, 3 Nov 2025 09:33:18 +0800
Subject: [PATCH 4/4] rename
---
.../bugprone/BugproneTidyModule.cpp | 6 +-
.../clang-tidy/bugprone/CMakeLists.txt | 2 +-
....cpp => StdNamespaceModificationCheck.cpp} | 6 +-
...heck.h => StdNamespaceModificationCheck.h} | 12 +-
.../clang-tidy/cert/CERTTidyModule.cpp | 4 +-
clang-tools-extra/docs/ReleaseNotes.rst | 4 +-
...ace.rst => std-namespace-modification.rst} | 12 +-
.../docs/clang-tidy/checks/cert/dcl58-cpp.rst | 2 +-
.../docs/clang-tidy/checks/list.rst | 4 +-
.../Inputs/Headers/system-header-simulation.h | 2 +-
.../bugprone/dont-modify-std-namespace.cpp | 283 ------------------
11 files changed, 27 insertions(+), 310 deletions(-)
rename clang-tools-extra/clang-tidy/bugprone/{DontModifyStdNamespaceCheck.cpp => StdNamespaceModificationCheck.cpp} (96%)
rename clang-tools-extra/clang-tidy/bugprone/{DontModifyStdNamespaceCheck.h => StdNamespaceModificationCheck.h} (66%)
rename clang-tools-extra/docs/clang-tidy/checks/bugprone/{dont-modify-std-namespace.rst => std-namespace-modification.rst} (89%)
delete mode 100644 clang-tools-extra/test/clang-tidy/checkers/bugprone/dont-modify-std-namespace.cpp
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 6f30e4e232c81..5f0742d618df3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -25,7 +25,6 @@
#include "CrtpConstructorAccessibilityCheck.h"
#include "DanglingHandleCheck.h"
#include "DerivedMethodShadowingBaseMethodCheck.h"
-#include "DontModifyStdNamespaceCheck.h"
#include "DynamicStaticInitializersCheck.h"
#include "EasilySwappableParametersCheck.h"
#include "EmptyCatchCheck.h"
@@ -72,6 +71,7 @@
#include "SizeofExpressionCheck.h"
#include "SpuriouslyWakeUpFunctionsCheck.h"
#include "StandaloneEmptyCheck.h"
+#include "StdNamespaceModificationCheck.h"
#include "StringConstructorCheck.h"
#include "StringIntegerAssignmentCheck.h"
#include "StringLiteralWithEmbeddedNulCheck.h"
@@ -142,8 +142,6 @@ class BugproneModule : public ClangTidyModule {
"bugprone-dangling-handle");
CheckFactories.registerCheck<DerivedMethodShadowingBaseMethodCheck>(
"bugprone-derived-method-shadowing-base-method");
- CheckFactories.registerCheck<DontModifyStdNamespaceCheck>(
- "bugprone-dont-modify-std-namespace");
CheckFactories.registerCheck<DynamicStaticInitializersCheck>(
"bugprone-dynamic-static-initializers");
CheckFactories.registerCheck<EasilySwappableParametersCheck>(
@@ -234,6 +232,8 @@ class BugproneModule : public ClangTidyModule {
"bugprone-spuriously-wake-up-functions");
CheckFactories.registerCheck<StandaloneEmptyCheck>(
"bugprone-standalone-empty");
+ CheckFactories.registerCheck<StdNamespaceModificationCheck>(
+ "bugprone-std-namespace-modification");
CheckFactories.registerCheck<StringConstructorCheck>(
"bugprone-string-constructor");
CheckFactories.registerCheck<StringIntegerAssignmentCheck>(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 358a73f36c9e6..882e9aa708d4d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -21,7 +21,6 @@ add_clang_library(clangTidyBugproneModule STATIC
CrtpConstructorAccessibilityCheck.cpp
DanglingHandleCheck.cpp
DerivedMethodShadowingBaseMethodCheck.cpp
- DontModifyStdNamespaceCheck.cpp
DynamicStaticInitializersCheck.cpp
EasilySwappableParametersCheck.cpp
EmptyCatchCheck.cpp
@@ -74,6 +73,7 @@ add_clang_library(clangTidyBugproneModule STATIC
SmartPtrArrayMismatchCheck.cpp
SpuriouslyWakeUpFunctionsCheck.cpp
StandaloneEmptyCheck.cpp
+ StdNamespaceModificationCheck.cpp
StringConstructorCheck.cpp
StringIntegerAssignmentCheck.cpp
StringLiteralWithEmbeddedNulCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/bugprone/DontModifyStdNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StdNamespaceModificationCheck.cpp
similarity index 96%
rename from clang-tools-extra/clang-tidy/bugprone/DontModifyStdNamespaceCheck.cpp
rename to clang-tools-extra/clang-tidy/bugprone/StdNamespaceModificationCheck.cpp
index 869120a9a0864..13e5c03d7c4d3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DontModifyStdNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StdNamespaceModificationCheck.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "DontModifyStdNamespaceCheck.h"
+#include "StdNamespaceModificationCheck.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchersInternal.h"
@@ -38,7 +38,7 @@ AST_POLYMORPHIC_MATCHER_P(
namespace clang::tidy::bugprone {
-void DontModifyStdNamespaceCheck::registerMatchers(MatchFinder *Finder) {
+void StdNamespaceModificationCheck::registerMatchers(MatchFinder *Finder) {
auto HasStdParent =
hasDeclContext(namespaceDecl(hasAnyName("std", "posix"),
unless(hasParent(namespaceDecl())))
@@ -108,7 +108,7 @@ static const NamespaceDecl *getTopLevelLexicalNamespaceDecl(const Decl *D) {
return LastNS;
}
-void clang::tidy::bugprone::DontModifyStdNamespaceCheck::check(
+void clang::tidy::bugprone::StdNamespaceModificationCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *D = Result.Nodes.getNodeAs<Decl>("decl");
const auto *NS = Result.Nodes.getNodeAs<NamespaceDecl>("nmspc");
diff --git a/clang-tools-extra/clang-tidy/bugprone/DontModifyStdNamespaceCheck.h b/clang-tools-extra/clang-tidy/bugprone/StdNamespaceModificationCheck.h
similarity index 66%
rename from clang-tools-extra/clang-tidy/bugprone/DontModifyStdNamespaceCheck.h
rename to clang-tools-extra/clang-tidy/bugprone/StdNamespaceModificationCheck.h
index 751b2fd98c87b..0f62dc3d9ab70 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DontModifyStdNamespaceCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/StdNamespaceModificationCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DONTMODIFYSTDNAMESPACECHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DONTMODIFYSTDNAMESPACECHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STDNAMESPACEMODIFICATIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STDNAMESPACEMODIFICATIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -17,10 +17,10 @@ namespace clang::tidy::bugprone {
/// This check warns for such modifications.
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/dont-modify-std-namespace.html
-class DontModifyStdNamespaceCheck : public ClangTidyCheck {
+/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/std-namespace-modification.html
+class StdNamespaceModificationCheck : public ClangTidyCheck {
public:
- DontModifyStdNamespaceCheck(StringRef Name, ClangTidyContext *Context)
+ StdNamespaceModificationCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
@@ -31,4 +31,4 @@ class DontModifyStdNamespaceCheck : public ClangTidyCheck {
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DONTMODIFYSTDNAMESPACECHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STDNAMESPACEMODIFICATIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
index cdd3a8b54f99b..7fa95f05779e8 100644
--- a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
@@ -11,13 +11,13 @@
#include "../ClangTidyModuleRegistry.h"
#include "../bugprone/BadSignalToKillThreadCheck.h"
#include "../bugprone/CommandProcessorCheck.h"
-#include "../bugprone/DontModifyStdNamespaceCheck.h"
#include "../bugprone/PointerArithmeticOnPolymorphicObjectCheck.h"
#include "../bugprone/ReservedIdentifierCheck.h"
#include "../bugprone/SignalHandlerCheck.h"
#include "../bugprone/SignedCharMisuseCheck.h"
#include "../bugprone/SizeofExpressionCheck.h"
#include "../bugprone/SpuriouslyWakeUpFunctionsCheck.h"
+#include "../bugprone/StdNamespaceModificationCheck.h"
#include "../bugprone/SuspiciousMemoryComparisonCheck.h"
#include "../bugprone/ThrowingStaticInitializationCheck.h"
#include "../bugprone/UncheckedStringToNumberConversionCheck.h"
@@ -251,7 +251,7 @@ class CERTModule : public ClangTidyModule {
"cert-dcl51-cpp");
CheckFactories.registerCheck<misc::NewDeleteOverloadsCheck>(
"cert-dcl54-cpp");
- CheckFactories.registerCheck<bugprone::DontModifyStdNamespaceCheck>(
+ CheckFactories.registerCheck<bugprone::StdNamespaceModificationCheck>(
"cert-dcl58-cpp");
CheckFactories.registerCheck<google::build::UnnamedNamespaceInHeaderCheck>(
"cert-dcl59-cpp");
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index d1702bb9286de..b9c18cc3033bf 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -245,8 +245,8 @@ New check aliases
keeping initial check as an alias to the new one.
- Renamed :doc:`cert-dcl58-cpp <clang-tidy/checks/cert/dcl58-cpp>` to
- :doc:`bugprone-dont-modify-std-namespace
- <clang-tidy/checks/bugprone/dont-modify-std-namespace>`
+ :doc:`bugprone-std-namespace-modification
+ <clang-tidy/checks/bugprone/std-namespace-modification>`
keeping initial check as an alias to the new one.
- Renamed :doc:`cert-env33-c <clang-tidy/checks/cert/env33-c>` to
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/dont-modify-std-namespace.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/std-namespace-modification.rst
similarity index 89%
rename from clang-tools-extra/docs/clang-tidy/checks/bugprone/dont-modify-std-namespace.rst
rename to clang-tools-extra/docs/clang-tidy/checks/bugprone/std-namespace-modification.rst
index 9293fa0a42763..c6e5608280264 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/dont-modify-std-namespace.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/std-namespace-modification.rst
@@ -1,11 +1,11 @@
-.. title:: clang-tidy - bugprone-dont-modify-std-namespace
+.. title:: clang-tidy - bugprone-std-namespace-modification
-bugprone-dont-modify-std-namespace
-==================================
+bugprone-std-namespace-modification
+===================================
+
+Warns on modifications of the ``std`` or ``posix`` namespaces which can
+result in undefined behavior.
-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).
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/dcl58-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/dcl58-cpp.rst
index ed2e4ec383c2e..1b8c2c4f97dde 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/dcl58-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/dcl58-cpp.rst
@@ -4,7 +4,7 @@ cert-dcl58-cpp
==============
The `cert-dcl58-cpp` is an aliaes, please see
-`bugprone-dont-modify-std-namespace <../bugprone/dont-modify-std-namespace.html>`_
+`bugprone-std-namespace-modification <../bugprone/std-namespace-modification.html>`_
for more information.
This check corresponds to the CERT C++ Coding Standard rule
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 056ed07516fb1..da815d124e9b6 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -93,7 +93,6 @@ Clang-Tidy Checks
:doc:`bugprone-crtp-constructor-accessibility <bugprone/crtp-constructor-accessibility>`, "Yes"
:doc:`bugprone-dangling-handle <bugprone/dangling-handle>`,
:doc:`bugprone-derived-method-shadowing-base-method <bugprone/derived-method-shadowing-base-method>`,
- :doc:`bugprone-dont-modify-std-namespace <bugprone/dont-modify-std-namespace>`,
:doc:`bugprone-dynamic-static-initializers <bugprone/dynamic-static-initializers>`,
:doc:`bugprone-easily-swappable-parameters <bugprone/easily-swappable-parameters>`,
:doc:`bugprone-empty-catch <bugprone/empty-catch>`,
@@ -140,6 +139,7 @@ Clang-Tidy Checks
:doc:`bugprone-sizeof-expression <bugprone/sizeof-expression>`,
:doc:`bugprone-spuriously-wake-up-functions <bugprone/spuriously-wake-up-functions>`,
:doc:`bugprone-standalone-empty <bugprone/standalone-empty>`, "Yes"
+ :doc:`bugprone-std-namespace-modification <bugprone/std-namespace-modification>`,
:doc:`bugprone-string-constructor <bugprone/string-constructor>`, "Yes"
:doc:`bugprone-string-integer-assignment <bugprone/string-integer-assignment>`, "Yes"
:doc:`bugprone-string-literal-with-embedded-nul <bugprone/string-literal-with-embedded-nul>`,
@@ -441,7 +441,7 @@ Check aliases
:doc:`cert-dcl50-cpp <cert/dcl50-cpp>`, :doc:`modernize-avoid-variadic-functions <modernize/avoid-variadic-functions>`,
:doc:`cert-dcl51-cpp <cert/dcl51-cpp>`, :doc:`bugprone-reserved-identifier <bugprone/reserved-identifier>`, "Yes"
:doc:`cert-dcl54-cpp <cert/dcl54-cpp>`, :doc:`misc-new-delete-overloads <misc/new-delete-overloads>`,
- :doc:`cert-dcl58-cpp <cert/dcl58-cpp>`, :doc:`bugprone-dont-modify-std-namespace <bugprone/dont-modify-std-namespace>`,
+ :doc:`cert-dcl58-cpp <cert/dcl58-cpp>`, :doc:`bugprone-std-namespace-modification <bugprone/std-namespace-modification>`,
:doc:`cert-dcl59-cpp <cert/dcl59-cpp>`, :doc:`google-build-namespaces <google/build-namespaces>`,
:doc:`cert-err09-cpp <cert/err09-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
:doc:`cert-env33-c <cert/env33-c>`, :doc:`bugprone-command-processor <bugprone/command-processor>`,
diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-header-simulation.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-header-simulation.h
index 2c4293dafb3e2..0870f60eaa39b 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-header-simulation.h
+++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-header-simulation.h
@@ -59,7 +59,7 @@ struct X {};
} // namespace std
// Template specializations that are in a system-header file.
-// The purpose is to test bugprone-dont-modify-std-namespace (no warnings here).
+// The purpose is to test bugprone-std-namespace-modification (no warnings here).
namespace std {
template <>
void swap<short>(short &, short &){};
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/dont-modify-std-namespace.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/dont-modify-std-namespace.cpp
deleted file mode 100644
index a53ba37d5ac95..0000000000000
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/dont-modify-std-namespace.cpp
+++ /dev/null
@@ -1,283 +0,0 @@
-// RUN: %check_clang_tidy -std=c++17-or-later %s bugprone-dont-modify-std-namespace %t -- -- -I %clang_tidy_headers
-
-#include "system-header-simulation.h"
-
-namespace A {
- namespace B {
- int b;
- }
-}
-
-namespace A {
- namespace B {
- int c;
- }
-}
-
-namespace posix {
-// CHECK-MESSAGES: :[[@LINE+2]]:11: warning: modification of 'posix' namespace can result in undefined behavior [bugprone-dont-modify-std-namespace]
-// CHECK-MESSAGES: :[[@LINE-2]]:11: note: 'posix' namespace opened here
-namespace foo {
-int foobar;
-}
-}
-
-namespace std {
-// CHECK-MESSAGES: :[[@LINE+2]]:5: warning: modification of 'std' namespace
-// CHECK-MESSAGES: :[[@LINE-2]]:11: note: 'std' namespace opened here
-int stdInt;
-// CHECK-MESSAGES: :[[@LINE+2]]:5: warning: modification of 'std' namespace
-// CHECK-MESSAGES: :[[@LINE-5]]:11: note: 'std' namespace opened here
-int stdInt1;
-}
-
-namespace foobar {
- namespace std {
- int bar;
- }
-}
-
-namespace posix {
-// CHECK-MESSAGES: :[[@LINE+2]]:11: warning: modification of 'posix' namespace
-// CHECK-MESSAGES: :[[@LINE-2]]:11: note: 'posix' namespace opened here
-namespace std {
-}
-} // namespace posix
-
-namespace posix::a {
-// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: modification of 'posix' namespace
-// CHECK-MESSAGES: :[[@LINE-2]]:11: note: 'posix' namespace opened here
-}
-
-namespace std {
-// no-warning: empty
-} // namespace std
-
-namespace std {
-// Warn for non-NamedDecls as well.
-// CHECK-MESSAGES: :[[@LINE+2]]:1: warning: modification of 'std' namespace
-// CHECK-MESSAGES: :[[@LINE-3]]:11: note: 'std' namespace opened here
-static_assert(1 == 1, "non-NamedDecl");
-} // namespace std
-
-enum class MyError {
- ErrorA,
- ErrorB
-};
-
-namespace std {
-// no-warning: Class template specialized by a program-defined type.
-template <>
-struct is_error_code_enum<MyError> : std::true_type {};
-
-// no-warning: Function template specialized by a program-defined type.
-template<>
-void swap<MyError>(MyError &a, MyError &b);
-}
-
-using ConstBoolPtr = const bool *;
-
-namespace std {
-// class template, builtin type
-// CHECK-MESSAGES: :[[@LINE+3]]:8: warning: modification of 'std' namespace
-// CHECK-MESSAGES: :[[@LINE-3]]:11: note: 'std' namespace opened here
-template <>
-struct is_error_code_enum<bool> : std::true_type {};
-// function template, builtin type
-// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: modification of 'std' namespace
-// CHECK-MESSAGES: :[[@LINE-8]]:11: note: 'std' namespace opened here
-template <>
-void swap<bool>(bool &, bool &);
-// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: modification of 'std' namespace
-// CHECK-MESSAGES: :[[@LINE-12]]:11: note: 'std' namespace opened here
-template <>
-void swap<ConstBoolPtr>(ConstBoolPtr &, ConstBoolPtr &);
-} // namespace std
-
-namespace std {
-// class template, std type
-// CHECK-MESSAGES: :[[@LINE+3]]:8: warning: modification of 'std' namespace
-// CHECK-MESSAGES: :[[@LINE-3]]:11: note: 'std' namespace opened here
-template <>
-struct is_error_code_enum<std::io_errc> : std::true_type {};
-// function template, std type
-// CHECK-MESSAGES: :[[@LINE+3]]:6: warning: modification of 'std' namespace
-// CHECK-MESSAGES: :[[@LINE-8]]:11: note: 'std' namespace opened here
-template <>
-void swap<std::io_errc>(std::io_errc &, std::io_errc &);
-} // namespace std
-
-// parameter pack, has program-defined type
-namespace std {
-// no-warning: there is one program-defined type.
-template <>
-class tuple<int, MyError, std::io_errc> {};
-} // namespace std
-
-// parameter pack, only builtin or std type
-namespace std {
-// Forbid variadic specializations over only `std::` or builtin types.
-// CHECK-MESSAGES: :[[@LINE+3]]:7: warning: modification of 'std' namespace
-// CHECK-MESSAGES: :[[@LINE-3]]:11: note: 'std' namespace opened here
-template <>
-class tuple<int, const std::io_errc, float> {};
-} // namespace std
-
-namespace std {
-// Test nested standard declarations.
-// CHECK-MESSAGES: :[[@LINE+3]]:8: warning: modification of 'std' namespace
-// CHECK-MESSAGES: :[[@LINE-3]]:11: note: 'std' namespace opened here
-template <>
-struct is_error_code_enum<std::Outer::Inner> : std::true_type {};
-} // namespace std
-
-namespace std {
-// Test nested namespace.
-// CHECK-MESSAGES: :[[@LINE+3]]:8: warning: modification of 'std' namespace
-// CHECK-MESSAGES: :[[@LINE-3]]:11: note: 'std' namespace opened here
-template <>
-struct is_error_code_enum<std::detail::X> : std::true_type {};
-} // namespace std
-
-// Test member function template specializations.
-namespace std {
-// CHECK-MESSAGES: :[[@LINE+3]]:18: warning: modification of 'std' namespace
-// CHECK_MESSAGES: :[[@LINE-2]]:11: note: 'std' namespace opened here
-template <>
-bool less<void>::operator()<int &&, float &&>(int &&, float &&) const {
- return true;
-}
-// CHECK-MESSAGES: :[[@LINE+3]]:18: warning: modification of 'std' namespace
-// CHECK_MESSAGES: :[[@LINE-8]]:11: note: 'std' namespace opened here
-template <>
-bool less<void>::operator()<MyError &&, MyError &&>(MyError &&, MyError &&) const {
- return true;
-}
-} // namespace std
-
-// Test member class template specializations.
-namespace std {
-// CHECK-MESSAGES: :[[@LINE+3]]:20: warning: modification of 'std' namespace
-// CHECK_MESSAGES: :[[@LINE-2]]:11: note: 'std' namespace opened here
-template <>
-struct less<void>::X<bool> {};
-// CHECK-MESSAGES: :[[@LINE+3]]:20: warning: modification of 'std' namespace
-// CHECK_MESSAGES: :[[@LINE-6]]:11: note: 'std' namespace opened here
-template <>
-struct less<void>::X<MyError> {};
-// CHECK-MESSAGES: :[[@LINE+3]]:20: warning: modification of 'std' namespace
-// CHECK_MESSAGES: :[[@LINE-10]]:11: note: 'std' namespace opened here
-template <typename T>
-struct less<void>::X<MyError, T> {};
-} // namespace std
-
-// We did not open the 'std' namespace, but still specialized the member
-// function of 'std::less'.
-// CHECK-MESSAGES: :[[@LINE+3]]:23: warning: modification of 'std' namespace
-// no-note: There is no opening of 'std' namespace, hence no note emitted.
-template <>
-bool std::less<void>::operator()<int &&, int &&>(int &&, int &&) const {
- return true;
-}
-
-namespace SpaceA {
-namespace SpaceB {
-class MapKey {
- int Type = 0;
-
-public:
- MapKey() = default;
- int getType() const { return Type; }
-};
-} // namespace SpaceB
-} // namespace SpaceA
-
-// no-warning: Specializing for 'std::hash' for a program-defined type.
-template <>
-struct std::hash<::SpaceA::SpaceB::MapKey> {
- // no-warning
- unsigned long operator()(const ::SpaceA::SpaceB::MapKey &K) const {
- return K.getType();
- }
- // no-warning
- bool operator()(const ::SpaceA::SpaceB::MapKey &K1,
- const ::SpaceA::SpaceB::MapKey &K2) const {
- return K1.getType() < K2.getType();
- }
-};
-
-using myint = int;
-
-// The type alias declaration is the same as typedef, does not introduce a
-// program-defined type.
-// CHECK-MESSAGES: :[[@LINE+2]]:13: warning: modification of 'std' namespace
-template <>
-struct std::hash<myint> {
- // no-warning: The warning was already reported for the struct itself.
- unsigned long operator()(const myint &K) const {
- return K;
- }
- // no-warning: The warning was already reported for the struct itself.
- bool operator()(const myint &K1,
- const myint &K2) const {
- return K1 < K2;
- }
-};
-
-// CHECK-MESSAGES: :[[@LINE+2]]:15: warning: modification of 'std' namespace
-template <>
-struct ::std::hash<long> {
- unsigned long operator()(const long &K) const {
- return K;
- }
-};
-
-namespace ranges {
-namespace detail {
-struct diffmax_t {};
-using LongT = long;
-} // namespace detail
-} // namespace ranges
-
-namespace std {
-// no-warning: specialization with an user-defined type
-template <>
-struct numeric_limits<::ranges::detail::diffmax_t> {
- static constexpr bool is_signed = true;
- static constexpr bool is_integer = true;
- static constexpr ::ranges::detail::diffmax_t max() noexcept {
- return {};
- }
-};
-inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::is_signed;
-inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::is_integer;
-} // namespace std
-
-namespace std {
-// specialization with type alias to non-program-defined-type
-// CHECK-MESSAGES: :[[@LINE+3]]:8: warning: modification of 'std' namespace
-// CHECK_MESSAGES: :[[@LINE-3]]:11: note: 'std' namespace opened here
-template <>
-struct numeric_limits<::ranges::detail::LongT> {
- static constexpr bool is_signed = true;
- static constexpr bool is_integer = true;
- static constexpr ::ranges::detail::LongT max() noexcept {
- return 1;
- }
-};
-inline constexpr bool numeric_limits<::ranges::detail::LongT>::is_signed;
-inline constexpr bool numeric_limits<::ranges::detail::LongT>::is_integer;
-} // namespace std
-
-namespace no_crash {
-struct A
-{
- friend struct B;
-};
-
-struct B;
-
-template<typename> struct T {};
-
-T<B> b;
-}
More information about the cfe-commits
mailing list