[PATCH] D69388: [clang-tidy] Fix modernize-use-nodiscard check for classes marked as [[nodiscard]]
Eugene Sedykh via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 28 09:10:38 PDT 2019
sedykh.eugene updated this revision to Diff 226677.
sedykh.eugene added a comment.
I removed using. Not a big deal. Thank you for the reviews!
Repository:
rCTE Clang Tools Extra
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D69388/new/
https://reviews.llvm.org/D69388
Files:
clang-tidy/modernize/UseNodiscardCheck.cpp
test/clang-tidy/checkers/modernize-use-nodiscard.cpp
Index: test/clang-tidy/checkers/modernize-use-nodiscard.cpp
===================================================================
--- test/clang-tidy/checkers/modernize-use-nodiscard.cpp
+++ test/clang-tidy/checkers/modernize-use-nodiscard.cpp
@@ -23,6 +23,8 @@
typedef unsigned &my_unsigned_reference;
typedef const unsigned &my_unsigned_const_reference;
+struct NO_DISCARD NoDiscardStruct{};
+
class Foo {
public:
using size_type = unsigned;
@@ -160,6 +162,9 @@
// Do not add ``[[nodiscard]]`` to conversion functions.
// explicit operator bool() const { return true; }
+
+ // Do not add ``[[nodiscard]]`` to functions returning types marked [[nodiscard]].
+ NoDiscardStruct f50() const;
};
// Do not add ``[[nodiscard]]`` to Lambda.
Index: clang-tidy/modernize/UseNodiscardCheck.cpp
===================================================================
--- clang-tidy/modernize/UseNodiscardCheck.cpp
+++ clang-tidy/modernize/UseNodiscardCheck.cpp
@@ -100,7 +100,9 @@
cxxMethodDecl(
allOf(isConst(), isDefinitionOrInline(),
unless(anyOf(
- returns(voidType()), isNoReturn(), isOverloadedOperator(),
+ returns(voidType()),
+ returns(hasDeclaration(decl(hasAttr(clang::attr::WarnUnusedResult)))),
+ isNoReturn(), isOverloadedOperator(),
isVariadic(), hasTemplateReturnType(),
hasClassMutableFields(), isConversionOperator(),
hasAttr(clang::attr::WarnUnusedResult),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69388.226677.patch
Type: text/x-patch
Size: 1568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191028/7fa29e7f/attachment.bin>
More information about the cfe-commits
mailing list