[clang-tools-extra] 808674f - [clang-tidy] Fix option serialization in misc-throw-by-value-catch-by-reference (#184750)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 5 05:27:31 PST 2026
Author: mitchell
Date: 2026-03-05T21:27:27+08:00
New Revision: 808674f7b20f7e2b6588d1f42061a154a6dcd4ed
URL: https://github.com/llvm/llvm-project/commit/808674f7b20f7e2b6588d1f42061a154a6dcd4ed
DIFF: https://github.com/llvm/llvm-project/commit/808674f7b20f7e2b6588d1f42061a154a6dcd4ed.diff
LOG: [clang-tidy] Fix option serialization in misc-throw-by-value-catch-by-reference (#184750)
Correct the serialization of the `WarnOnLargeObject` and
`CheckThrowTemporaries` options in `storeOptions`.
Added:
clang-tools-extra/test/clang-tidy/checkers/misc/throw-by-value-catch-by-reference-options.cpp
Modified:
clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp b/clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
index fc739a020c1ef..51ceceec6b65e 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 fc104987fc8ec..b461f764eb0db 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -231,6 +231,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:`misc-unused-using-decls
<clang-tidy/checks/misc/unused-using-decls>` to not diagnose ``using``
declarations as unused if they're exported from a module.
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
+}
More information about the cfe-commits
mailing list