Author: Ayokunle Amodu Date: 2026-02-21T19:42:41-08:00 New Revision: 76af74004e8bd1be55dc3b6b497575492fc47586
URL: https://github.com/llvm/llvm-project/commit/76af74004e8bd1be55dc3b6b497575492fc47586 DIFF: https://github.com/llvm/llvm-project/commit/76af74004e8bd1be55dc3b6b497575492fc47586.diff LOG: [clang][diagnostics] Refactor `warn_doc_function_method_decl_mismatch` to use enum_select (#181769) Related: https://github.com/llvm/llvm-project/issues/123121 This patch refactors the `warn_doc_function_method_decl_mismatch` diagnostic to use `enum_select` instead of `select`. This gets rid of magic numbers in its caller and improves readability. Added: Modified: clang/include/clang/Basic/DiagnosticCommentKinds.td clang/lib/AST/CommentSema.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Basic/DiagnosticCommentKinds.td b/clang/include/clang/Basic/DiagnosticCommentKinds.td index 588cd3615e7e6..c6daa1e6d24d4 100644 --- a/clang/include/clang/Basic/DiagnosticCommentKinds.td +++ b/clang/include/clang/Basic/DiagnosticCommentKinds.td @@ -77,7 +77,9 @@ def warn_doc_param_not_attached_to_a_function_decl : Warning< InGroup<Documentation>, DefaultIgnore; def warn_doc_function_method_decl_mismatch : Warning< - "'%select{\\|@}0%select{function|functiongroup|method|methodgroup|callback}1' " + "'%select{\\|@}0%enum_select<CallableKind>{" + "%Function{function}|%FunctionGroup{functiongroup}|" + "%Method{method}|%MethodGroup{methodgroup}|%Callback{callback}}1' " "command should be used in a comment attached to " "%select{a function|a function|an Objective-C method|an Objective-C method|" "a pointer to function}2 declaration">, diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp index d5ba240cb2bde..c7fb6c96fd46f 100644 --- a/clang/lib/AST/CommentSema.cpp +++ b/clang/lib/AST/CommentSema.cpp @@ -100,32 +100,30 @@ void Sema::checkFunctionDeclVerbatimLine(const BlockCommandComment *Comment) { if (!Info->IsFunctionDeclarationCommand) return; - unsigned DiagSelect; + std::optional<unsigned> DiagSelect; switch (Comment->getCommandID()) { case CommandTraits::KCI_function: - DiagSelect = (!isAnyFunctionDecl() && !isFunctionTemplateDecl())? 1 : 0; + if (!isAnyFunctionDecl() && !isFunctionTemplateDecl()) + DiagSelect = diag::CallableKind::Function; break; case CommandTraits::KCI_functiongroup: - DiagSelect = (!isAnyFunctionDecl() && !isFunctionTemplateDecl())? 2 : 0; + if (!isAnyFunctionDecl() && !isFunctionTemplateDecl()) + DiagSelect = diag::CallableKind::FunctionGroup; break; case CommandTraits::KCI_method: - DiagSelect = !isObjCMethodDecl() ? 3 : 0; + DiagSelect = diag::CallableKind::Method; break; case CommandTraits::KCI_methodgroup: - DiagSelect = !isObjCMethodDecl() ? 4 : 0; + DiagSelect = diag::CallableKind::MethodGroup; break; case CommandTraits::KCI_callback: - DiagSelect = !isFunctionPointerVarDecl() ? 5 : 0; - break; - default: - DiagSelect = 0; + DiagSelect = diag::CallableKind::Callback; break; } if (DiagSelect) Diag(Comment->getLocation(), diag::warn_doc_function_method_decl_mismatch) - << Comment->getCommandMarker() - << (DiagSelect-1) << (DiagSelect-1) - << Comment->getSourceRange(); + << Comment->getCommandMarker() << (*DiagSelect) << (*DiagSelect) + << Comment->getSourceRange(); } void Sema::checkContainerDeclVerbatimLine(const BlockCommandComment *Comment) { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
