summaryrefslogtreecommitdiff
path: root/clang/lib/AST/CommentSema.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2020-01-17 20:45:01 +0000
committerDimitry Andric <dim@FreeBSD.org>2020-01-17 20:45:01 +0000
commit706b4fc47bbc608932d3b491ae19a3b9cde9497b (patch)
tree4adf86a776049cbf7f69a1929c4babcbbef925eb /clang/lib/AST/CommentSema.cpp
parent7cc9cf2bf09f069cb2dd947ead05d0b54301fb71 (diff)
Notes
Diffstat (limited to 'clang/lib/AST/CommentSema.cpp')
-rw-r--r--clang/lib/AST/CommentSema.cpp53
1 files changed, 35 insertions, 18 deletions
diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp
index 69d61dc55162..53c1832d1dd2 100644
--- a/clang/lib/AST/CommentSema.cpp
+++ b/clang/lib/AST/CommentSema.cpp
@@ -676,9 +676,8 @@ void Sema::checkDeprecatedCommand(const BlockCommandComment *Command) {
D->hasAttr<UnavailableAttr>())
return;
- Diag(Command->getLocation(),
- diag::warn_doc_deprecated_not_sync)
- << Command->getSourceRange();
+ Diag(Command->getLocation(), diag::warn_doc_deprecated_not_sync)
+ << Command->getSourceRange() << Command->getCommandMarker();
// Try to emit a fixit with a deprecation attribute.
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
@@ -689,24 +688,41 @@ void Sema::checkDeprecatedCommand(const BlockCommandComment *Command) {
FD->doesThisDeclarationHaveABody())
return;
- StringRef AttributeSpelling = "__attribute__((deprecated))";
+ const LangOptions &LO = FD->getASTContext().getLangOpts();
+ const bool DoubleSquareBracket = LO.CPlusPlus14 || LO.C2x;
+ StringRef AttributeSpelling =
+ DoubleSquareBracket ? "[[deprecated]]" : "__attribute__((deprecated))";
if (PP) {
- TokenValue Tokens[] = {
- tok::kw___attribute, tok::l_paren, tok::l_paren,
- PP->getIdentifierInfo("deprecated"),
- tok::r_paren, tok::r_paren
- };
- StringRef MacroName = PP->getLastMacroWithSpelling(FD->getLocation(),
- Tokens);
- if (!MacroName.empty())
- AttributeSpelling = MacroName;
+ // Try to find a replacement macro:
+ // - In C2x/C++14 we prefer [[deprecated]].
+ // - If not found or an older C/C++ look for __attribute__((deprecated)).
+ StringRef MacroName;
+ if (DoubleSquareBracket) {
+ TokenValue Tokens[] = {tok::l_square, tok::l_square,
+ PP->getIdentifierInfo("deprecated"),
+ tok::r_square, tok::r_square};
+ MacroName = PP->getLastMacroWithSpelling(FD->getLocation(), Tokens);
+ if (!MacroName.empty())
+ AttributeSpelling = MacroName;
+ }
+
+ if (MacroName.empty()) {
+ TokenValue Tokens[] = {
+ tok::kw___attribute, tok::l_paren,
+ tok::l_paren, PP->getIdentifierInfo("deprecated"),
+ tok::r_paren, tok::r_paren};
+ StringRef MacroName =
+ PP->getLastMacroWithSpelling(FD->getLocation(), Tokens);
+ if (!MacroName.empty())
+ AttributeSpelling = MacroName;
+ }
}
- SmallString<64> TextToInsert(" ");
- TextToInsert += AttributeSpelling;
- Diag(FD->getEndLoc(), diag::note_add_deprecation_attr)
- << FixItHint::CreateInsertion(FD->getEndLoc().getLocWithOffset(1),
- TextToInsert);
+ SmallString<64> TextToInsert = AttributeSpelling;
+ TextToInsert += " ";
+ SourceLocation Loc = FD->getSourceRange().getBegin();
+ Diag(Loc, diag::note_add_deprecation_attr)
+ << FixItHint::CreateInsertion(Loc, TextToInsert);
}
}
@@ -1127,6 +1143,7 @@ Sema::getInlineCommandRenderKind(StringRef Name) const {
.Case("b", InlineCommandComment::RenderBold)
.Cases("c", "p", InlineCommandComment::RenderMonospaced)
.Cases("a", "e", "em", InlineCommandComment::RenderEmphasized)
+ .Case("anchor", InlineCommandComment::RenderAnchor)
.Default(InlineCommandComment::RenderNormal);
}