diff options
author | Mark de Wever <koraq@xs4all.nl> | 2019-12-10 18:32:30 +0100 |
---|---|---|
committer | Mark de Wever <koraq@xs4all.nl> | 2019-12-10 21:16:18 +0100 |
commit | b6d386f6f996394ec24c5d0ebe84131c89237594 (patch) | |
tree | fe382b344bfba6035a1f4e178816472f6e830f48 /clang/lib/AST/CommentSema.cpp | |
parent | b972f2d05e8b39dd84e586756e7078d79134e2fb (diff) | |
download | bcm5719-llvm-b6d386f6f996394ec24c5d0ebe84131c89237594.tar.gz bcm5719-llvm-b6d386f6f996394ec24c5d0ebe84131c89237594.zip |
[Wdocumentation] Use C2x/C++14 deprecated attribute
This replaces the non-standard __attribute__((deprecated)) with the
standard [[deprecated]] when compiling in C2x/C++14 mode.
Discovered while looking at https://bugs.llvm.org/show_bug.cgi?id=43753
Differential Revision: https://reviews.llvm.org/D71141
Diffstat (limited to 'clang/lib/AST/CommentSema.cpp')
-rw-r--r-- | clang/lib/AST/CommentSema.cpp | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp index d0c98e6de45..dda31e90601 100644 --- a/clang/lib/AST/CommentSema.cpp +++ b/clang/lib/AST/CommentSema.cpp @@ -688,17 +688,34 @@ 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 = AttributeSpelling; |