[clang] [clang][Sema] Refine unused-member-function diagnostic message for constructors (PR #84515)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 29 09:43:43 PDT 2025
================
@@ -402,7 +402,7 @@ def warn_unused_function : Warning<"unused function %0">,
InGroup<UnusedFunction>, DefaultIgnore;
def warn_unused_template : Warning<"unused %select{function|variable}0 template %1">,
InGroup<UnusedTemplate>, DefaultIgnore;
-def warn_unused_member_function : Warning<"unused member function %0">,
+def warn_unused_member_function : Warning<"unused %select{constructor|member function %1}0">,
----------------
guillem-bartrina-sonarsource wrote:
Hello @AaronBallman, and thanks for this recommendation.
I clearly see the advantages it brings, namely refining the message also for other special members and avoiding having to do the type test for the different nodes at the diagnosis creation site.
However, note that only *default* constructors are considered “special members” (see `CXXSpecialMemberKind`). Therefore, using this trick would not avoid having to manually spell `constructor` in the template because it would still be necessary to treat them specially. The trick would just refine the message for other special members with little additional effort.
The template would then be something like
```text
def warn_unused_member_function : Warning<"unused %select{"
"member function %1|"
"constructor|"
"%sub{select_special_member_kind}1}0">,
InGroup<UnusedMemberFunction>, DefaultIgnore;
```
WDYT?
https://github.com/llvm/llvm-project/pull/84515
More information about the cfe-commits
mailing list