summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/modernize-use-nodiscard-cxx11.cpp
diff options
context:
space:
mode:
authorJonas Toth <jonas.toth@gmail.com>2019-01-09 20:50:50 +0000
committerJonas Toth <jonas.toth@gmail.com>2019-01-09 20:50:50 +0000
commitca8e20cdf76b5cc59159c315d35e6968f8879cb3 (patch)
treefb48861015f27e612d4d277edc2d5b637603c3cd /clang-tools-extra/test/clang-tidy/modernize-use-nodiscard-cxx11.cpp
parent67796064c76e921de8a5c07a25cecafc215d71e2 (diff)
downloadbcm5719-llvm-ca8e20cdf76b5cc59159c315d35e6968f8879cb3.tar.gz
bcm5719-llvm-ca8e20cdf76b5cc59159c315d35e6968f8879cb3.zip
[clang-tidy] Adding a new modernize use nodiscard checker
Summary: Adds a checker to clang-tidy to warn when a non void const member function, taking only parameters passed by value or const reference could be marked as '[[nodiscard]]' Patch by MyDeveloperDay. Reviewers: alexfh, stephenkelly, curdeius, aaron.ballman, hokein, JonasToth Reviewed By: curdeius, JonasToth Subscribers: Eugene.Zelenko, lefticus, lebedev.ri, mgorny, xazax.hun, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D55433 llvm-svn: 350760
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/modernize-use-nodiscard-cxx11.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/modernize-use-nodiscard-cxx11.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/modernize-use-nodiscard-cxx11.cpp b/clang-tools-extra/test/clang-tidy/modernize-use-nodiscard-cxx11.cpp
new file mode 100644
index 00000000000..1a72bf4936a
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/modernize-use-nodiscard-cxx11.cpp
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s modernize-use-nodiscard %t -- \
+// RUN: -config="{CheckOptions: [{key: modernize-use-nodiscard.ReplacementString, value: '__attribute__((warn_unused_result))'}]}" \
+// RUN: -- -std=c++11 \
+
+class Foo
+{
+public:
+ bool f1() const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f1' should be marked __attribute__((warn_unused_result)) [modernize-use-nodiscard]
+ // CHECK-FIXES: __attribute__((warn_unused_result)) bool f1() const;
+
+ bool f2(int) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f2' should be marked __attribute__((warn_unused_result)) [modernize-use-nodiscard]
+ // CHECK-FIXES: __attribute__((warn_unused_result)) bool f2(int) const;
+
+ bool f3(const int &) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f3' should be marked __attribute__((warn_unused_result)) [modernize-use-nodiscard]
+ // CHECK-FIXES: __attribute__((warn_unused_result)) bool f3(const int &) const;
+
+ bool f4(void) const;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f4' should be marked __attribute__((warn_unused_result)) [modernize-use-nodiscard]
+ // CHECK-FIXES: __attribute__((warn_unused_result)) bool f4(void) const;
+};
+
OpenPOWER on IntegriCloud