diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2016-03-07 22:44:55 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2016-03-07 22:44:55 +0000 |
commit | e7964789dabaa5b9fb26c50f54deafb7fb8db4d6 (patch) | |
tree | e9284db077152c2c9222edb213e39ebbb193ef7d /clang/lib/AST/Decl.cpp | |
parent | 146c14ac33136ebff2714f4596f6d7db85d6b5e8 (diff) | |
download | bcm5719-llvm-e7964789dabaa5b9fb26c50f54deafb7fb8db4d6.tar.gz bcm5719-llvm-e7964789dabaa5b9fb26c50f54deafb7fb8db4d6.zip |
Implement support for [[nodiscard]] in C++1z that is based off existing support for warn_unused_result, and treat it as an extension pre-C++1z. This also means extending the existing warn_unused_result attribute so that it can be placed on an enum as well as a class.
llvm-svn: 262872
Diffstat (limited to 'clang/lib/AST/Decl.cpp')
-rw-r--r-- | clang/lib/AST/Decl.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 041b530bf07..abaec2d7e10 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -2935,16 +2935,22 @@ SourceRange FunctionDecl::getReturnTypeSourceRange() const { return RTRange; } -bool FunctionDecl::hasUnusedResultAttr() const { +const Attr *FunctionDecl::getUnusedResultAttr() const { QualType RetType = getReturnType(); if (RetType->isRecordType()) { const CXXRecordDecl *Ret = RetType->getAsCXXRecordDecl(); const auto *MD = dyn_cast<CXXMethodDecl>(this); - if (Ret && Ret->hasAttr<WarnUnusedResultAttr>() && - !(MD && MD->getCorrespondingMethodInClass(Ret, true))) - return true; + if (Ret && !(MD && MD->getCorrespondingMethodInClass(Ret, true))) { + if (const auto *R = Ret->getAttr<WarnUnusedResultAttr>()) + return R; + } + } else if (const auto *ET = RetType->getAs<EnumType>()) { + if (const EnumDecl *ED = ET->getDecl()) { + if (const auto *R = ED->getAttr<WarnUnusedResultAttr>()) + return R; + } } - return hasAttr<WarnUnusedResultAttr>(); + return getAttr<WarnUnusedResultAttr>(); } /// \brief For an inline function definition in C, or for a gnu_inline function |