[clang-tools-extra] [clang-tidy] Don't suggest removing [[maybe_unused]] variables in performance-unnecessary-copy-initialization (PR #244978)

Zeyi Xu via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 23 19:02:02 PST 2026


================
@@ -771,6 +771,21 @@ void positiveUnusedReferenceIsRemoved() {
   // CHECK-FIXES: // Comments on a new line should not be deleted.
 }
 
+void positiveMaybeUnusedIsNotRemoved() {
+  [[maybe_unused]] auto FromCall = ExpensiveTypeReference();
+  // CHECK-MESSAGES: [[@LINE-1]]:25: warning: the variable 'FromCall' of type 'ExpensiveToCopyType' is copy-constructed from a const reference but is only used as const reference; consider making it a const reference [performance-unnecessary-copy-initialization]
----------------
zeyi2 wrote:

This diagnostics might be a bit misleading?

It says that `FromCall` is only used as a const reference, even though it has no uses at all.

https://github.com/llvm/llvm-project/pull/244978


More information about the cfe-commits mailing list