[clang-tools-extra] [clang-tidy] add AllowedTypes option to misc-const-correctness (PR #122951)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 31 13:49:18 PST 2025
https://github.com/vbvictor updated https://github.com/llvm/llvm-project/pull/122951
>From 618f4a1707c1b62693c0e878040997154e7e35d6 Mon Sep 17 00:00:00 2001
From: Victor Baranov <bar.victor.2002 at gmail.com>
Date: Tue, 14 Jan 2025 22:05:43 +0300
Subject: [PATCH 1/9] [clang-tidy] add AllowedTypes to misc-const-correctness
---
.../clang-tidy/misc/ConstCorrectnessCheck.cpp | 18 +-
.../clang-tidy/misc/ConstCorrectnessCheck.h | 2 +
clang-tools-extra/docs/ReleaseNotes.rst | 5 +
.../checks/misc/const-correctness.rst | 10 +
.../misc/const-correctness-allowed-types.cpp | 180 ++++++++++++++++++
5 files changed, 213 insertions(+), 2 deletions(-)
create mode 100644 clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-allowed-types.cpp
diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 71a4cee4bdc6ef..aee4a3b789863c 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -8,6 +8,8 @@
#include "ConstCorrectnessCheck.h"
#include "../utils/FixItHintUtils.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
@@ -41,7 +43,9 @@ ConstCorrectnessCheck::ConstCorrectnessCheck(StringRef Name,
TransformValues(Options.get("TransformValues", true)),
TransformReferences(Options.get("TransformReferences", true)),
TransformPointersAsValues(
- Options.get("TransformPointersAsValues", false)) {
+ Options.get("TransformPointersAsValues", false)),
+ AllowedTypes(
+ utils::options::parseStringList(Options.get("AllowedTypes", ""))) {
if (AnalyzeValues == false && AnalyzeReferences == false)
this->configurationDiag(
"The check 'misc-const-correctness' will not "
@@ -57,6 +61,9 @@ void ConstCorrectnessCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "TransformValues", TransformValues);
Options.store(Opts, "TransformReferences", TransformReferences);
Options.store(Opts, "TransformPointersAsValues", TransformPointersAsValues);
+
+ Options.store(Opts, "AllowedTypes",
+ utils::options::serializeStringList(AllowedTypes));
}
void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
@@ -73,6 +80,12 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
hasType(referenceType(pointee(hasCanonicalType(templateTypeParmType())))),
hasType(referenceType(pointee(substTemplateTypeParmType()))));
+ const auto AllowedType = hasType(qualType(anyOf(
+ hasDeclaration(namedDecl(matchers::matchesAnyListedName(AllowedTypes))),
+ references(namedDecl(matchers::matchesAnyListedName(AllowedTypes))),
+ pointerType(pointee(hasDeclaration(
+ namedDecl(matchers::matchesAnyListedName(AllowedTypes))))))));
+
const auto AutoTemplateType = varDecl(
anyOf(hasType(autoType()), hasType(referenceType(pointee(autoType()))),
hasType(pointerType(pointee(autoType())))));
@@ -87,7 +100,8 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
unless(anyOf(ConstType, ConstReference, TemplateType,
hasInitializer(isInstantiationDependent()), AutoTemplateType,
RValueReference, FunctionPointerRef,
- hasType(cxxRecordDecl(isLambda())), isImplicit())));
+ hasType(cxxRecordDecl(isLambda())), isImplicit(),
+ AllowedType)));
// Match the function scope for which the analysis of all local variables
// shall be run.
diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
index bba060e555d001..3b7aba7c4be384 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
@@ -45,6 +45,8 @@ class ConstCorrectnessCheck : public ClangTidyCheck {
const bool TransformValues;
const bool TransformReferences;
const bool TransformPointersAsValues;
+
+ const std::vector<StringRef> AllowedTypes;
};
} // namespace clang::tidy::misc
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 3bddeeda06e06b..f57e951afc1ce0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -101,6 +101,11 @@ Changes in existing checks
<clang-tidy/checks/bugprone/unsafe-functions>` check to allow specifying
additional C++ member functions to match.
+- Improved :doc:`misc-const-correctness
+ <clang-tidy/checks/misc/const-correctness>` check by adding
+ the option ``AllowedTypes``, that excludes specified types
+ from const-correctness checking.
+
Removed checks
^^^^^^^^^^^^^^
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
index 8ac1ad56bc8cf7..201f6252816f04 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
@@ -196,3 +196,13 @@ Options
// The following pointer may not become a 'int *const'.
int *changing_pointee = &value;
changing_pointee = &result;
+
+.. option:: AllowedTypes (default = '')
+
+ A semicolon-separated list of names of types that
+ will be excluded from const-correctness checking.
+ Regular expressions are accepted, e.g. `[Rr]ef(erence)?$` matches every type
+ with suffix `Ref`, `ref`, `Reference` and `reference`.
+ If a name in the list contains the sequence `::` it is matched against
+ the qualified typename (i.e. `namespace::Type`), otherwise it is matched
+ against only the type name (i.e. `Type`).
\ No newline at end of file
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-allowed-types.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-allowed-types.cpp
new file mode 100644
index 00000000000000..a73b4a08d0a711
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-allowed-types.cpp
@@ -0,0 +1,180 @@
+// RUN: %check_clang_tidy %s misc-const-correctness %t -- \
+// RUN: -config="{CheckOptions: {\
+// RUN: misc-const-correctness.AllowedTypes: '[Pp]ointer$;[Pp]tr$;[Rr]ef(erence)?$;qualified::Type;::fully::QualifiedType;ConstTemplate', \
+// RUN: misc-const-correctness.TransformPointersAsValues: true, \
+// RUN: misc-const-correctness.TransformReferences: true, \
+// RUN: misc-const-correctness.WarnPointersAsValues: true } \
+// RUN: }" -- -fno-delayed-template-parsing
+
+struct SmartPointer {
+};
+
+struct smart_pointer {
+};
+
+struct SmartPtr {
+};
+
+struct smart_ptr {
+};
+
+struct SmartReference {
+};
+
+struct smart_reference {
+};
+
+struct SmartRef {
+};
+
+struct smart_ref {
+};
+
+struct OtherType {
+};
+
+template <typename T> struct ConstTemplate {
+};
+
+namespace qualified {
+struct Type {
+};
+} // namespace qualified
+
+namespace fully {
+struct QualifiedType {
+};
+} // namespace fully
+
+void negativeSmartPointer() {
+ SmartPointer p1 = {};
+ SmartPointer* p2 = {};
+ SmartPointer& p3 = p1;
+}
+
+void negative_smart_pointer() {
+ smart_pointer p1 = {};
+ smart_pointer* p2 = {};
+ smart_pointer& p3 = p1;
+}
+
+void negativeSmartPtr() {
+ SmartPtr p1 = {};
+ SmartPtr* p2 = {};
+ SmartPtr& p3 = p1;
+}
+
+void negative_smart_ptr() {
+ smart_ptr p1 = {};
+ smart_ptr* p2 = {};
+ smart_ptr& p3 = p1;
+}
+
+void negativeSmartReference() {
+ SmartReference p1 = {};
+ SmartReference* p2 = {};
+ SmartReference& p3 = p1;
+}
+
+void negative_smart_reference() {
+ smart_reference p1 = {};
+ smart_reference* p2 = {};
+ smart_reference& p3 = p1;
+}
+
+void negativeSmartRef() {
+ SmartRef p1 = {};
+ SmartRef* p2 = {};
+ SmartRef& p3 = p1;
+}
+
+void negative_smart_ref() {
+ smart_ref p1 = {};
+ smart_ref* p2 = {};
+ smart_ref& p3 = p1;
+}
+
+void positiveOtherType() {
+ OtherType t = {};
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 't' of type 'OtherType' can be declared 'const'
+ // CHECK-FIXES: OtherType const t = {};
+}
+
+void negativeSomeComplex() {
+ ConstTemplate<int> t1 = {};
+ ConstTemplate<int>* t2 = {};
+ ConstTemplate<int>& t3 = t1;
+}
+
+void negativeQualified() {
+ qualified::Type t1 = {};
+ qualified::Type* t2 = {};
+ qualified::Type& t3 = t1;
+
+ using qualified::Type;
+ Type t4 = {};
+ Type* t5 = {};
+ Type& t6 = t4;
+}
+
+void negativeFullyQualified() {
+ fully::QualifiedType t1 = {};
+ fully::QualifiedType* t2 = {};
+ fully::QualifiedType& t3 = t1;
+
+ using fully::QualifiedType;
+ QualifiedType t4 = {};
+ QualifiedType* t5 = {};
+ QualifiedType& t6 = t4;
+}
+
+using MySP = SmartPointer;
+using MyTemplate = ConstTemplate<int>;
+template <typename T> using MyTemplate2 = ConstTemplate<T>;
+
+void positiveTypedefs() {
+ MySP p1 = {};
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p1' of type 'MySP' (aka 'SmartPointer') can be declared 'const'
+ // CHECK-FIXES: MySP const p1 = {};
+
+ MySP* p2 = {};
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p2' of type 'MySP *' (aka 'SmartPointer *') can be declared 'const'
+ // CHECK-FIXES: MySP* const p2 = {};
+
+ MySP& p3 = p1;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p3' of type 'MySP &' (aka 'SmartPointer &') can be declared 'const'
+ // CHECK-FIXES: MySP const& p3 = p1;
+
+ MyTemplate t1 = {};
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 't1' of type 'MyTemplate' (aka 'ConstTemplate<int>') can be declared 'const'
+ // CHECK-FIXES: MyTemplate const t1 = {};
+
+ MyTemplate* t2 = {};
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 't2' of type 'MyTemplate *' (aka 'ConstTemplate<int> *') can be declared 'const'
+ // CHECK-FIXES: MyTemplate* const t2 = {};
+
+ MyTemplate& t3 = t1;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 't3' of type 'MyTemplate &' (aka 'ConstTemplate<int> &') can be declared 'const'
+ // CHECK-FIXES: MyTemplate const& t3 = t1;
+
+ MyTemplate2<int> t4 = {};
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 't4' of type 'MyTemplate2<int>' (aka 'ConstTemplate<int>') can be declared 'const'
+ // CHECK-FIXES: MyTemplate2<int> const t4 = {};
+
+ MyTemplate2<int>* t5 = {};
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 't5' of type 'MyTemplate2<int> *' (aka 'ConstTemplate<int> *') can be declared 'const'
+ // CHECK-FIXES: MyTemplate2<int>* const t5 = {};
+
+ MyTemplate2<int>& t6 = t4;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 't6' of type 'MyTemplate2<int> &' (aka 'ConstTemplate<int> &') can be declared 'const'
+ // CHECK-FIXES: MyTemplate2<int> const& t6 = t4;
+}
+
+template <typename T>
+class Vector {};
+
+void positiveSmartPtrWrapped() {
+ Vector<SmartPtr> vec = {};
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'vec' of type 'Vector<SmartPtr>' can be declared 'const'
+ // CHECK-FIXES: Vector<SmartPtr> const vec = {};
+}
>From 1650450b0eb19412239561949ac80a758496750d Mon Sep 17 00:00:00 2001
From: Victor Baranov <bar.victor.2002 at gmail.com>
Date: Wed, 15 Jan 2025 08:36:27 +0300
Subject: [PATCH 2/9] [clang-tidy] fix pr comments
---
clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp | 1 -
clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h | 1 -
.../docs/clang-tidy/checks/misc/const-correctness.rst | 6 +++---
3 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index aee4a3b789863c..6e412e576e5f98 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -61,7 +61,6 @@ void ConstCorrectnessCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "TransformValues", TransformValues);
Options.store(Opts, "TransformReferences", TransformReferences);
Options.store(Opts, "TransformPointersAsValues", TransformPointersAsValues);
-
Options.store(Opts, "AllowedTypes",
utils::options::serializeStringList(AllowedTypes));
}
diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
index 3b7aba7c4be384..87dddc4faf7814 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
@@ -45,7 +45,6 @@ class ConstCorrectnessCheck : public ClangTidyCheck {
const bool TransformValues;
const bool TransformReferences;
const bool TransformPointersAsValues;
-
const std::vector<StringRef> AllowedTypes;
};
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
index 201f6252816f04..6ebc2da180bce4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
@@ -203,6 +203,6 @@ Options
will be excluded from const-correctness checking.
Regular expressions are accepted, e.g. `[Rr]ef(erence)?$` matches every type
with suffix `Ref`, `ref`, `Reference` and `reference`.
- If a name in the list contains the sequence `::` it is matched against
- the qualified typename (i.e. `namespace::Type`), otherwise it is matched
- against only the type name (i.e. `Type`).
\ No newline at end of file
+ If a name in the list contains the sequence `::`, it is matched against
+ the qualified type name (i.e. `namespace::Type`), otherwise it is matched
+ against only the type name (i.e. `Type`).
>From f677e2cc881b0a32bd61d3b4fd7424887d6fab63 Mon Sep 17 00:00:00 2001
From: Baranov Victor <bar.victor.2002 at gmail.com>
Date: Wed, 15 Jan 2025 20:20:25 +0300
Subject: [PATCH 3/9] [clang-tidy] fix pr comments
---
clang-tools-extra/docs/ReleaseNotes.rst | 2 +-
.../docs/clang-tidy/checks/misc/const-correctness.rst | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index f57e951afc1ce0..c870f2c3a2613b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -103,7 +103,7 @@ Changes in existing checks
- Improved :doc:`misc-const-correctness
<clang-tidy/checks/misc/const-correctness>` check by adding
- the option ``AllowedTypes``, that excludes specified types
+ the option `AllowedTypes`, that excludes specified types
from const-correctness checking.
Removed checks
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
index 6ebc2da180bce4..df6b7b1cae6c5f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
@@ -205,4 +205,4 @@ Options
with suffix `Ref`, `ref`, `Reference` and `reference`.
If a name in the list contains the sequence `::`, it is matched against
the qualified type name (i.e. `namespace::Type`), otherwise it is matched
- against only the type name (i.e. `Type`).
+ against only the type name (i.e. ``Type``).
>From 8b20960aae46c0da77b0e3f1154c05b677081d96 Mon Sep 17 00:00:00 2001
From: Baranov Victor <bar.victor.2002 at gmail.com>
Date: Wed, 15 Jan 2025 20:23:49 +0300
Subject: [PATCH 4/9] [clang-tidy] fix pr comments
---
.../docs/clang-tidy/checks/misc/const-correctness.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
index df6b7b1cae6c5f..cbaeeb96c5c276 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
@@ -204,5 +204,5 @@ Options
Regular expressions are accepted, e.g. `[Rr]ef(erence)?$` matches every type
with suffix `Ref`, `ref`, `Reference` and `reference`.
If a name in the list contains the sequence `::`, it is matched against
- the qualified type name (i.e. `namespace::Type`), otherwise it is matched
+ the qualified type name (i.e. ``namespace::Type``), otherwise it is matched
against only the type name (i.e. ``Type``).
>From 846d59df61acefe93d7c1b7af3088f50090daf70 Mon Sep 17 00:00:00 2001
From: Victor Baranov <bar.victor.2002 at gmail.com>
Date: Sat, 25 Jan 2025 20:10:46 +0300
Subject: [PATCH 5/9] [clang-tidy] improved docs by filling lines to
80-character limit
---
clang-tools-extra/docs/ReleaseNotes.rst | 6 +++---
.../clang-tidy/checks/misc/const-correctness.rst | 13 ++++++-------
2 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index c870f2c3a2613b..eba306fcdc6bc8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -102,9 +102,9 @@ Changes in existing checks
additional C++ member functions to match.
- Improved :doc:`misc-const-correctness
- <clang-tidy/checks/misc/const-correctness>` check by adding
- the option `AllowedTypes`, that excludes specified types
- from const-correctness checking.
+ <clang-tidy/checks/misc/const-correctness>` check by adding the option
+ `AllowedTypes`, that excludes specified types from const-correctness
+ checking.
Removed checks
^^^^^^^^^^^^^^
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
index cbaeeb96c5c276..c67c79a97f62f6 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
@@ -199,10 +199,9 @@ Options
.. option:: AllowedTypes (default = '')
- A semicolon-separated list of names of types that
- will be excluded from const-correctness checking.
- Regular expressions are accepted, e.g. `[Rr]ef(erence)?$` matches every type
- with suffix `Ref`, `ref`, `Reference` and `reference`.
- If a name in the list contains the sequence `::`, it is matched against
- the qualified type name (i.e. ``namespace::Type``), otherwise it is matched
- against only the type name (i.e. ``Type``).
+ A semicolon-separated list of names of types that will be excluded from
+ const-correctness checking. Regular expressions are accepted, e.g.
+ `[Rr]ef(erence)?$` matches every type with suffix `Ref`, `ref`, `Reference`
+ and `reference`. If a name in the list contains the sequence `::`, it is
+ matched against the qualified type name (i.e. ``namespace::Type``),
+ otherwise it is matched against only the type name (i.e. ``Type``).
>From 4533c32da2659fc3fb410baaa84858b606c84338 Mon Sep 17 00:00:00 2001
From: Victor Baranov <bar.victor.2002 at gmail.com>
Date: Mon, 27 Jan 2025 18:42:36 +0300
Subject: [PATCH 6/9] [clang-tidy] fix pr docs comments
---
.../docs/clang-tidy/checks/misc/const-correctness.rst | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
index c67c79a97f62f6..31f413937782d0 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
@@ -197,7 +197,7 @@ Options
int *changing_pointee = &value;
changing_pointee = &result;
-.. option:: AllowedTypes (default = '')
+.. option:: AllowedTypes
A semicolon-separated list of names of types that will be excluded from
const-correctness checking. Regular expressions are accepted, e.g.
@@ -205,3 +205,4 @@ Options
and `reference`. If a name in the list contains the sequence `::`, it is
matched against the qualified type name (i.e. ``namespace::Type``),
otherwise it is matched against only the type name (i.e. ``Type``).
+ Default is empty.
>From 44abe9383460fa28fcf5127a34bbcfe4435b4f00 Mon Sep 17 00:00:00 2001
From: Victor Baranov <bar.victor.2002 at gmail.com>
Date: Mon, 27 Jan 2025 19:02:41 +0300
Subject: [PATCH 7/9] [clang-tidy] fixed styles of default parameters in docs
---
.../checks/misc/const-correctness.rst | 31 ++++++++++---------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
index 31f413937782d0..276f7776224192 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
@@ -80,9 +80,10 @@ This limitation affects the capability to add ``const`` to methods which is not
Options
-------
-.. option:: AnalyzeValues (default = true)
+.. option:: AnalyzeValues
- Enable or disable the analysis of ordinary value variables, like ``int i = 42;``
+ Enable or disable the analysis of ordinary value variables, like
+ ``int i = 42;``. Default is `true`.
.. code-block:: c++
@@ -96,9 +97,10 @@ Options
// No warning
int const a[] = {42, 42, 42};
-.. option:: AnalyzeReferences (default = true)
+.. option:: AnalyzeReferences
- Enable or disable the analysis of reference variables, like ``int &ref = i;``
+ Enable or disable the analysis of reference variables, like
+ ``int &ref = i;``. Default is `true`.
.. code-block:: c++
@@ -108,11 +110,11 @@ Options
// No warning
int const& ref = i;
-.. option:: WarnPointersAsValues (default = false)
+.. option:: WarnPointersAsValues
This option enables the suggestion for ``const`` of the pointer itself.
Pointer values have two possibilities to be ``const``, the pointer
- and the value pointing to.
+ and the value pointing to. Default is `false`.
.. code-block:: c++
@@ -123,9 +125,10 @@ Options
// No warning
const int *const pointer_variable = &value;
-.. option:: TransformValues (default = true)
+.. option:: TransformValues
- Provides fixit-hints for value types that automatically add ``const`` if its a single declaration.
+ Provides fixit-hints for value types that automatically add ``const`` if
+ its a single declaration. Default is `true`.
.. code-block:: c++
@@ -143,10 +146,10 @@ Options
int result = value * 3;
result -= 10;
-.. option:: TransformReferences (default = true)
+.. option:: TransformReferences
- Provides fixit-hints for reference types that automatically add ``const`` if its a single
- declaration.
+ Provides fixit-hints for reference types that automatically add ``const`` if
+ its a single declaration. Default is `true`.
.. code-block:: c++
@@ -163,10 +166,10 @@ Options
int result = ref_value * 3;
result -= 10;
-.. option:: TransformPointersAsValues (default = false)
+.. option:: TransformPointersAsValues
- Provides fixit-hints for pointers if their pointee is not changed. This does not analyze if the
- value-pointed-to is unchanged!
+ Provides fixit-hints for pointers if their pointee is not changed. This does
+ not analyze if the value-pointed-to is unchanged! Default is `false`.
Requires 'WarnPointersAsValues' to be 'true'.
>From c67a51ee3e1804d5042da08a81854f677827b03b Mon Sep 17 00:00:00 2001
From: Victor Baranov <bar.victor.2002 at gmail.com>
Date: Sat, 1 Feb 2025 00:44:18 +0300
Subject: [PATCH 8/9] [clang-tidy] fixed pr comments
---
.../docs/clang-tidy/checks/misc/const-correctness.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
index 276f7776224192..2c75cdf0dcafbb 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
@@ -208,4 +208,4 @@ Options
and `reference`. If a name in the list contains the sequence `::`, it is
matched against the qualified type name (i.e. ``namespace::Type``),
otherwise it is matched against only the type name (i.e. ``Type``).
- Default is empty.
+ Default is empty string.
>From 360df600f4f1ac18af472de9063ac685de1ab857 Mon Sep 17 00:00:00 2001
From: Victor Baranov <bar.victor.2002 at gmail.com>
Date: Sat, 1 Feb 2025 00:48:49 +0300
Subject: [PATCH 9/9] [clang-tidy] Added double ticks
---
.../docs/clang-tidy/checks/misc/const-correctness.rst | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
index 2c75cdf0dcafbb..2e7e0f3602ab9c 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
@@ -204,8 +204,8 @@ Options
A semicolon-separated list of names of types that will be excluded from
const-correctness checking. Regular expressions are accepted, e.g.
- `[Rr]ef(erence)?$` matches every type with suffix `Ref`, `ref`, `Reference`
- and `reference`. If a name in the list contains the sequence `::`, it is
- matched against the qualified type name (i.e. ``namespace::Type``),
- otherwise it is matched against only the type name (i.e. ``Type``).
- Default is empty string.
+ ``[Rr]ef(erence)?$`` matches every type with suffix ``Ref``, ``ref``,
+ ``Reference`` and ``reference``. If a name in the list contains the sequence
+ `::`, it is matched against the qualified type name
+ (i.e. ``namespace::Type``), otherwise it is matched against only the type
+ name (i.e. ``Type``). Default is empty string.
More information about the cfe-commits
mailing list