[clang-tools-extra] [clang-tidy][NFC] Update contribution guide for test language standards (PR #184769)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 5 02:52:55 PST 2026
https://github.com/zeyi2 created https://github.com/llvm/llvm-project/pull/184769
None
>From 46b368037f66f1225f169be79ee6855c0f930a59 Mon Sep 17 00:00:00 2001
From: mtx <mitchell.xu2 at gmail.com>
Date: Thu, 5 Mar 2026 14:43:41 +0800
Subject: [PATCH 1/2] [clang-tidy] Fix option serialization in
misc-throw-by-value-catch-by-reference
---
.../ThrowByValueCatchByReferenceCheck.cpp | 4 +-
clang-tools-extra/docs/ReleaseNotes.rst | 9 ++++
...ow-by-value-catch-by-reference-options.cpp | 50 +++++++++++++++++++
3 files changed, 61 insertions(+), 2 deletions(-)
create mode 100644 clang-tools-extra/test/clang-tidy/checkers/misc/throw-by-value-catch-by-reference-options.cpp
diff --git a/clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp b/clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
index db3a69029c069..fe4b050dd1edf 100644
--- a/clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
@@ -31,8 +31,8 @@ void ThrowByValueCatchByReferenceCheck::registerMatchers(MatchFinder *Finder) {
void ThrowByValueCatchByReferenceCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
- Options.store(Opts, "CheckThrowTemporaries", true);
- Options.store(Opts, "WarnOnLargeObjects", WarnOnLargeObject);
+ Options.store(Opts, "CheckThrowTemporaries", CheckAnonymousTemporaries);
+ Options.store(Opts, "WarnOnLargeObject", WarnOnLargeObject);
Options.store(Opts, "MaxSize", MaxSizeOptions);
}
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index cf8dd0dba9f12..1f95a22190d26 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -208,6 +208,15 @@ Changes in existing checks
- Fixed false positive where an array of pointers to ``const`` was
incorrectly diagnosed as allowing the pointee to be made ``const``.
+- Improved :doc:`misc-throw-by-value-catch-by-reference
+ <clang-tidy/checks/misc/throw-by-value-catch-by-reference>` check:
+
+ - Fixed the `WarnOnLargeObject` option to use the correct name when
+ storing the configuration.
+
+ - Fixed the `CheckThrowTemporaries` option to correctly reflect its
+ configured value in exported settings.
+
- Improved :doc:`modernize-pass-by-value
<clang-tidy/checks/modernize/pass-by-value>` check by adding `IgnoreMacros`
option to suppress warnings in macros.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/throw-by-value-catch-by-reference-options.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/throw-by-value-catch-by-reference-options.cpp
new file mode 100644
index 0000000000000..f06241447de4b
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/throw-by-value-catch-by-reference-options.cpp
@@ -0,0 +1,50 @@
+// RUN: %check_clang_tidy %s misc-throw-by-value-catch-by-reference %t -- \
+// RUN: -config="{CheckOptions: { \
+// RUN: misc-throw-by-value-catch-by-reference.WarnOnLargeObject: true, \
+// RUN: misc-throw-by-value-catch-by-reference.MaxSize: 200, \
+// RUN: misc-throw-by-value-catch-by-reference.CheckThrowTemporaries: false \
+// RUN: }}" -- -fcxx-exceptions
+
+struct LargeTrivial {
+ char data[100];
+};
+
+struct SmallTrivial {
+ char data[10];
+};
+
+struct NonTrivial {
+ NonTrivial() {}
+ NonTrivial(const NonTrivial &) {}
+ char data[100];
+};
+
+void testLargeTrivial() {
+ try {
+ throw LargeTrivial();
+ } catch (LargeTrivial e) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: catch handler catches by value; should catch by reference instead [misc-throw-by-value-catch-by-reference]
+ }
+}
+
+void testSmallTrivial() {
+ try {
+ throw SmallTrivial();
+ } catch (SmallTrivial e) {
+ // Should not warn (80 < 200)
+ }
+}
+
+void testNonTrivial() {
+ try {
+ throw NonTrivial();
+ } catch (NonTrivial e) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: catch handler catches by value; should catch by reference instead [misc-throw-by-value-catch-by-reference]
+ }
+}
+
+void testCheckThrowTemporaries() {
+ LargeTrivial lvalue;
+ throw lvalue;
+ // Should not warn when CheckThrowTemporaries is false
+}
>From 3ba36a8afc41d748ecc6215d4d6c876455f37781 Mon Sep 17 00:00:00 2001
From: mtx <mitchell.xu2 at gmail.com>
Date: Thu, 5 Mar 2026 18:52:38 +0800
Subject: [PATCH 2/2] [clang-tidy][NFC] Update contribution guide for test
language standards
---
.../docs/clang-tidy/Contributing.rst | 22 +++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/clang-tools-extra/docs/clang-tidy/Contributing.rst b/clang-tools-extra/docs/clang-tidy/Contributing.rst
index 72444480ece0e..d0cc43f9bbad9 100644
--- a/clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ b/clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -662,6 +662,28 @@ Here's an example:
// CHECK-FIXES-USING-B-NOT: using a::B;$
// CHECK-FIXES-NOT: using a::C;$
+Specifying the Language Standard
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The ``-std`` flag controls which C or C++ standard(s) the test is compiled
+under. It accepts a comma-separated list of standards and supports an
+``-or-later`` suffix:
+
+- ``-std=c++17``: runs the test **only** with C++17.
+- ``-std=c++17-or-later``: runs the test once for each standard from C++17
+ onwards (currently C++17, C++20, C++23, and C++26), in separate invocations.
+ Use this when a check should work correctly on all modern standards.
+- ``-std=c++14,c++17``: runs the test once with C++14 and once with C++17.
+
+When no ``-std`` is given, ``check_clang_tidy.py`` defaults to
+``c++11-or-later`` for C++ files and ``c99-or-later`` for C files. The check
+skeleton generated by ``add_new_check.py`` uses the ``-or-later`` form by
+default. Prefer ``-std=<minimum>-or-later`` unless the test expects
+behavior that only applies to a specific standard version.
+
+Common Pitfalls and Edge Cases
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
There are many dark corners in the C++ language, and it may be difficult to
make your check work perfectly in all cases, especially if it issues fix-it
hints. The most frequent pitfalls are macros and templates:
More information about the cfe-commits
mailing list