Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/include/clang/Basic/DiagnosticCommentKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def warn_doc_function_method_decl_mismatch : Warning<
InGroup<Documentation>, DefaultIgnore;

def warn_doc_api_container_decl_mismatch : Warning<
"'%select{\\|@}0%select{class|interface|protocol|struct|union}1' "
"'%select{\\|@}0%enum_select<DeclContainerKind>{%Class{class}"
"|%Interface{interface}|%Protocol{protocol}|%Struct{struct}|%Union{union}}1' "
"command should not be used in a comment attached to a "
"non-%select{class|interface|protocol|struct|union}2 declaration">,
InGroup<Documentation>, DefaultIgnore;
Expand Down
29 changes: 16 additions & 13 deletions clang/lib/AST/CommentSema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,39 +132,42 @@ void Sema::checkContainerDeclVerbatimLine(const BlockCommandComment *Comment) {
const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
if (!Info->IsRecordLikeDeclarationCommand)
return;
unsigned DiagSelect;
std::optional<unsigned> DiagSelect;
switch (Comment->getCommandID()) {
case CommandTraits::KCI_class:
DiagSelect =
(!isClassOrStructOrTagTypedefDecl() && !isClassTemplateDecl()) ? 1
: 0;
if (!isClassOrStructOrTagTypedefDecl() && !isClassTemplateDecl())
DiagSelect = diag::DeclContainerKind::Class;

// Allow @class command on @interface declarations.
// FIXME. Currently, \class and @class are indistinguishable. So,
// \class is also allowed on an @interface declaration
if (DiagSelect && Comment->getCommandMarker() && isObjCInterfaceDecl())
DiagSelect = 0;
DiagSelect = std::nullopt;
break;
case CommandTraits::KCI_interface:
DiagSelect = !isObjCInterfaceDecl() ? 2 : 0;
if (!isObjCInterfaceDecl())
DiagSelect = diag::DeclContainerKind::Interface;
break;
case CommandTraits::KCI_protocol:
DiagSelect = !isObjCProtocolDecl() ? 3 : 0;
if (!isObjCProtocolDecl())
DiagSelect = diag::DeclContainerKind::Protocol;
break;
case CommandTraits::KCI_struct:
DiagSelect = !isClassOrStructOrTagTypedefDecl() ? 4 : 0;
if (!isClassOrStructOrTagTypedefDecl())
DiagSelect = diag::DeclContainerKind::Struct;
break;
case CommandTraits::KCI_union:
DiagSelect = !isUnionDecl() ? 5 : 0;
if (!isUnionDecl())
DiagSelect = diag::DeclContainerKind::Union;
break;
default:
DiagSelect = 0;
DiagSelect = std::nullopt;
break;
}
if (DiagSelect)
Diag(Comment->getLocation(), diag::warn_doc_api_container_decl_mismatch)
<< Comment->getCommandMarker()
<< (DiagSelect-1) << (DiagSelect-1)
<< Comment->getSourceRange();
<< Comment->getCommandMarker() << (*DiagSelect) << (*DiagSelect)
<< Comment->getSourceRange();
}

void Sema::checkContainerDecl(const BlockCommandComment *Comment) {
Expand Down
Loading