[clang] [clang][Sema] Refine unused-member-function diagnostic message for constructors (PR #84515)

via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 9 03:47:19 PST 2024


================
@@ -1398,11 +1398,16 @@ void Sema::ActOnEndOfTranslationUnit() {
           if (FD->getDescribedFunctionTemplate())
             Diag(DiagD->getLocation(), diag::warn_unused_template)
                 << /*function=*/0 << DiagD << DiagRange;
-          else
-            Diag(DiagD->getLocation(), isa<CXXMethodDecl>(DiagD)
-                                           ? diag::warn_unused_member_function
-                                           : diag::warn_unused_function)
-                << DiagD << DiagRange;
+          else {
+            if (isa<CXXMethodDecl>(DiagD))
+              Diag(DiagD->getLocation(), diag::warn_unused_member_function)
+                  << (!isa<CXXConstructorDecl>(DiagD) ? /*member function=*/0
+                                                      : /*constructor=*/1)
+                  << DiagD << DiagRange;
+            else
+              Diag(DiagD->getLocation(), diag::warn_unused_function)
+                  << DiagD << DiagRange;
+          }
----------------
cor3ntin wrote:

```suggestion
          else {
            Diag(DiagD->getLocation(), isa<CXXMethodDecl>(DiagD)
                                           ? diag::warn_unused_member_function
                                           : diag::warn_unused_function)                        
                << DiagD 
                << (!isa<CXXConstructorDecl>(DiagD) ? /*member function=*/0
                                                                                    : /*constructor=*/1
                << DiagRange;
          }
```

I think you can simplify like that.
And then change ` warn_unused_member_function : Warning<"unused %select{member function|constructor}1 %0"`

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


More information about the cfe-commits mailing list