<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">This should be fixed by r327911.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Douglas Yung<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> cfe-commits [mailto:cfe-commits-bounces@lists.llvm.org]
<b>On Behalf Of </b>Galina Kistanova via cfe-commits<br>
<b>Sent:</b> Monday, March 19, 2018 13:13<br>
<b>To:</b> Alexander Kornienko<br>
<b>Cc:</b> cfe-commits<br>
<b>Subject:</b> Re: [clang-tools-extra] r327833 - [clang-tidy] New check bugprone-unused-return-value<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Hello Alexander,<br>
<br>
This commit broke at least two of our builders:<br>
<br>
<a href="http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/26909">http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/26909</a><br>
<a href="http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast">http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast</a><br>
<br>
. . . <br>
Failing Tests (1):<br>
Clang Tools :: clang-tidy/bugprone-unused-return-value.cpp<br>
<br>
Please have a look?<br>
<br>
It is not good idea to keep the bot red for too long. This hides new problem which later hard to track down.<br>
<br>
Thanks<br>
<br>
Galina<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Mon, Mar 19, 2018 at 6:02 AM, Alexander Kornienko via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<o:p></o:p></p>
<p class="MsoNormal">Author: alexfh<br>
Date: Mon Mar 19 06:02:32 2018<br>
New Revision: 327833<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=327833&view=rev" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=327833&view=rev</a><br>
Log:<br>
[clang-tidy] New check bugprone-unused-return-value<br>
<br>
Summary:<br>
Detects function calls where the return value is unused.<br>
<br>
Checked functions can be configured.<br>
<br>
Reviewers: alexfh, aaron.ballman, ilya-biryukov, hokein<br>
<br>
Reviewed By: alexfh, aaron.ballman<br>
<br>
Subscribers: hintonda, JonasToth, Eugene.Zelenko, mgorny, xazax.hun, cfe-commits<br>
<br>
Tags: #clang-tools-extra<br>
<br>
Patch by Kalle Huttunen!<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D41655" target="_blank">
https://reviews.llvm.org/D41655</a><br>
<br>
Added:<br>
clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.cpp<br>
clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.h<br>
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-unused-return-value.rst<br>
clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp<br>
clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp<br>
Modified:<br>
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp<br>
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt<br>
clang-tools-extra/trunk/docs/ReleaseNotes.rst<br>
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst<br>
<br>
Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=327833&r1=327832&r2=327833&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=327833&r1=327832&r2=327833&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp (original)<br>
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Mon Mar 19 06:02:32 2018<br>
@@ -43,6 +43,7 @@<br>
#include "UndefinedMemoryManipulationCheck.h"<br>
#include "UndelegatedConstructorCheck.h"<br>
#include "UnusedRaiiCheck.h"<br>
+#include "UnusedReturnValueCheck.h"<br>
#include "UseAfterMoveCheck.h"<br>
#include "VirtualNearMissCheck.h"<br>
<br>
@@ -119,6 +120,8 @@ public:<br>
"bugprone-undelegated-constructor");<br>
CheckFactories.registerCheck<UnusedRaiiCheck>(<br>
"bugprone-unused-raii");<br>
+ CheckFactories.registerCheck<UnusedReturnValueCheck>(<br>
+ "bugprone-unused-return-value");<br>
CheckFactories.registerCheck<UseAfterMoveCheck>(<br>
"bugprone-use-after-move");<br>
CheckFactories.registerCheck<VirtualNearMissCheck>(<br>
<br>
Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=327833&r1=327832&r2=327833&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=327833&r1=327832&r2=327833&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)<br>
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Mon Mar 19 06:02:32 2018<br>
@@ -35,6 +35,7 @@ add_clang_library(clangTidyBugproneModul<br>
UndefinedMemoryManipulationCheck.cpp<br>
UndelegatedConstructorCheck.cpp<br>
UnusedRaiiCheck.cpp<br>
+ UnusedReturnValueCheck.cpp<br>
UseAfterMoveCheck.cpp<br>
VirtualNearMissCheck.cpp<br>
<br>
<br>
Added: clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.cpp?rev=327833&view=auto" target="_blank">
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.cpp?rev=327833&view=auto</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.cpp (added)<br>
+++ clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.cpp Mon Mar 19 06:02:32 2018<br>
@@ -0,0 +1,82 @@<br>
+//===--- UnusedReturnValueCheck.cpp - clang-tidy---------------------------===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "UnusedReturnValueCheck.h"<br>
+#include "../utils/OptionsUtils.h"<br>
+#include "clang/AST/ASTContext.h"<br>
+#include "clang/ASTMatchers/ASTMatchFinder.h"<br>
+<br>
+using namespace clang::ast_matchers;<br>
+using namespace clang::ast_matchers::internal;<br>
+<br>
+namespace clang {<br>
+namespace tidy {<br>
+namespace bugprone {<br>
+<br>
+UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,<br>
+ ClangTidyContext *Context)<br>
+ : ClangTidyCheck(Name, Context),<br>
+ CheckedFunctions(Options.get("CheckedFunctions", "::std::async;"<br>
+ "::std::launder;"<br>
+ "::std::remove;"<br>
+ "::std::remove_if;"<br>
+ "::std::unique")) {}<br>
+<br>
+void UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {<br>
+ Options.store(Opts, "CheckedFunctions", CheckedFunctions);<br>
+}<br>
+<br>
+void UnusedReturnValueCheck::registerMatchers(MatchFinder *Finder) {<br>
+ auto FunVec = utils::options::parseStringList(CheckedFunctions);<br>
+ auto MatchedCallExpr = expr(ignoringImplicit(ignoringParenImpCasts(<br>
+ callExpr(<br>
+ callee(functionDecl(<br>
+ // Don't match void overloads of checked functions.<br>
+ unless(returns(voidType())), hasAnyName(std::vector<StringRef>(<br>
+ FunVec.begin(), FunVec.end())))))<br>
+ .bind("match"))));<br>
+<br>
+ auto UnusedInCompoundStmt =<br>
+ compoundStmt(forEach(MatchedCallExpr),<br>
+ // The checker can't currently differentiate between the<br>
+ // return statement and other statements inside GNU statement<br>
+ // expressions, so disable the checker inside them to avoid<br>
+ // false positives.<br>
+ unless(hasParent(stmtExpr())));<br>
+ auto UnusedInIfStmt =<br>
+ ifStmt(eachOf(hasThen(MatchedCallExpr), hasElse(MatchedCallExpr)));<br>
+ auto UnusedInWhileStmt = whileStmt(hasBody(MatchedCallExpr));<br>
+ auto UnusedInDoStmt = doStmt(hasBody(MatchedCallExpr));<br>
+ auto UnusedInForStmt =<br>
+ forStmt(eachOf(hasLoopInit(MatchedCallExpr),<br>
+ hasIncrement(MatchedCallExpr), hasBody(MatchedCallExpr)));<br>
+ auto UnusedInRangeForStmt = cxxForRangeStmt(hasBody(MatchedCallExpr));<br>
+ auto UnusedInCaseStmt = switchCase(forEach(MatchedCallExpr));<br>
+<br>
+ Finder->addMatcher(<br>
+ stmt(anyOf(UnusedInCompoundStmt, UnusedInIfStmt, UnusedInWhileStmt,<br>
+ UnusedInDoStmt, UnusedInForStmt, UnusedInRangeForStmt,<br>
+ UnusedInCaseStmt)),<br>
+ this);<br>
+}<br>
+<br>
+void UnusedReturnValueCheck::check(const MatchFinder::MatchResult &Result) {<br>
+ if (const auto *Matched = Result.Nodes.getNodeAs<CallExpr>("match")) {<br>
+ diag(Matched->getLocStart(),<br>
+ "the value returned by this function should be used")<br>
+ << Matched->getSourceRange();<br>
+ diag(Matched->getLocStart(),<br>
+ "cast the expression to void to silence this warning",<br>
+ DiagnosticIDs::Note);<br>
+ }<br>
+}<br>
+<br>
+} // namespace bugprone<br>
+} // namespace tidy<br>
+} // namespace clang<br>
<br>
Added: clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.h?rev=327833&view=auto" target="_blank">
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.h?rev=327833&view=auto</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.h (added)<br>
+++ clang-tools-extra/trunk/clang-tidy/bugprone/UnusedReturnValueCheck.h Mon Mar 19 06:02:32 2018<br>
@@ -0,0 +1,39 @@<br>
+//===--- UnusedReturnValueCheck.h - clang-tidy-------------------*- C++ -*-===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNUSEDRETURNVALUECHECK_H<br>
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNUSEDRETURNVALUECHECK_H<br>
+<br>
+#include "../ClangTidy.h"<br>
+#include <string><br>
+<br>
+namespace clang {<br>
+namespace tidy {<br>
+namespace bugprone {<br>
+<br>
+/// Detects function calls where the return value is unused.<br>
+///<br>
+/// For the user-facing documentation see:<br>
+/// <a href="http://clang.llvm.org/extra/clang-tidy/checks/bugprone-unused-return-value.html" target="_blank">
http://clang.llvm.org/extra/clang-tidy/checks/bugprone-unused-return-value.html</a><br>
+class UnusedReturnValueCheck : public ClangTidyCheck {<br>
+public:<br>
+ UnusedReturnValueCheck(StringRef Name, ClangTidyContext *Context);<br>
+ void storeOptions(ClangTidyOptions::OptionMap &Opts) override;<br>
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;<br>
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;<br>
+<br>
+private:<br>
+ std::string CheckedFunctions;<br>
+};<br>
+<br>
+} // namespace bugprone<br>
+} // namespace tidy<br>
+} // namespace clang<br>
+<br>
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNUSEDRETURNVALUECHECK_H<br>
<br>
Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=327833&r1=327832&r2=327833&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=327833&r1=327832&r2=327833&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)<br>
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Mon Mar 19 06:02:32 2018<br>
@@ -67,6 +67,11 @@ Improvements to clang-tidy<br>
Diagnoses when a temporary object that appears to be an exception is<br>
constructed but not thrown.<br>
<br>
+- New `bugprone-unused-return-value<br>
+ <<a href="http://clang.llvm.org/extra/clang-tidy/checks/bugprone-unused-return-value.html" target="_blank">http://clang.llvm.org/extra/clang-tidy/checks/bugprone-unused-return-value.html</a>>`_ check<br>
+<br>
+ Warns on unused function return values.<br>
+<br>
- New `cppcoreguidelines-avoid-goto<br>
<<a href="http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-avoid-goto.html" target="_blank">http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-avoid-goto.html</a>>`_ check<br>
<br>
<br>
Added: clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-unused-return-value.rst<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-unused-return-value.rst?rev=327833&view=auto" target="_blank">
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-unused-return-value.rst?rev=327833&view=auto</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-unused-return-value.rst (added)<br>
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-unused-return-value.rst Mon Mar 19 06:02:32 2018<br>
@@ -0,0 +1,24 @@<br>
+.. title:: clang-tidy - bugprone-unused-return-value<br>
+<br>
+bugprone-unused-return-value<br>
+============================<br>
+<br>
+Warns on unused function return values. The checked funtions can be configured.<br>
+<br>
+Options<br>
+-------<br>
+<br>
+.. option:: CheckedFunctions<br>
+<br>
+ Semicolon-separated list of functions to check. Defaults to<br>
+ ``::std::async;::std::launder;::std::remove;::std::remove_if;::std::unique``.<br>
+ This means that the calls to following functions are checked by default:<br>
+<br>
+ - ``std::async()``. Not using the return value makes the call synchronous.<br>
+ - ``std::launder()``. Not using the return value usually means that the<br>
+ function interface was misunderstood by the programmer. Only the returned<br>
+ pointer is "laundered", not the argument.<br>
+ - ``std::remove()``, ``std::remove_if()`` and ``std::unique()``. The returned<br>
+ iterator indicates the boundary between elements to keep and elements to be<br>
+ removed. Not using the return value means that the information about which<br>
+ elements to remove is lost.<br>
<br>
Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=327833&r1=327832&r2=327833&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=327833&r1=327832&r2=327833&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original)<br>
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Mon Mar 19 06:02:32 2018<br>
@@ -51,6 +51,7 @@ Clang-Tidy Checks<br>
bugprone-undefined-memory-manipulation<br>
bugprone-undelegated-constructor<br>
bugprone-unused-raii<br>
+ bugprone-unused-return-value<br>
bugprone-use-after-move<br>
bugprone-virtual-near-miss<br>
cert-dcl03-c (redirects to misc-static-assert) <cert-dcl03-c><br>
<br>
Added: clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp?rev=327833&view=auto" target="_blank">
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp?rev=327833&view=auto</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp (added)<br>
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value-custom.cpp Mon Mar 19 06:02:32 2018<br>
@@ -0,0 +1,82 @@<br>
+// RUN: %check_clang_tidy %s bugprone-unused-return-value %t \<br>
+// RUN: -config='{CheckOptions: \<br>
+// RUN: [{key: bugprone-unused-return-value.CheckedFunctions, \<br>
+// RUN: value: "::fun;::ns::Outer::Inner::memFun;::ns::Type::staticFun"}]}' \<br>
+// RUN: --<br>
+<br>
+namespace std {<br>
+<br>
+template <typename T><br>
+T *launder(T *);<br>
+<br>
+} // namespace std<br>
+<br>
+namespace ns {<br>
+<br>
+struct Outer {<br>
+ struct Inner {<br>
+ bool memFun();<br>
+ };<br>
+};<br>
+<br>
+using AliasName = Outer;<br>
+<br>
+struct Derived : public Outer::Inner {};<br>
+<br>
+struct Retval {<br>
+ int *P;<br>
+ Retval() { P = new int; }<br>
+ ~Retval() { delete P; }<br>
+};<br>
+<br>
+struct Type {<br>
+ Retval memFun();<br>
+ static Retval staticFun();<br>
+};<br>
+<br>
+} // namespace ns<br>
+<br>
+int fun();<br>
+void fun(int);<br>
+<br>
+void warning() {<br>
+ fun();<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+<br>
+ (fun());<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:4: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+<br>
+ ns::Outer::Inner ObjA1;<br>
+ ObjA1.memFun();<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+<br>
+ ns::AliasName::Inner ObjA2;<br>
+ ObjA2.memFun();<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+<br>
+ ns::Derived ObjA3;<br>
+ ObjA3.memFun();<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+<br>
+ ns::Type::staticFun();<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+}<br>
+<br>
+void noWarning() {<br>
+ auto R1 = fun();<br>
+<br>
+ ns::Outer::Inner ObjB1;<br>
+ auto R2 = ObjB1.memFun();<br>
+<br>
+ auto R3 = ns::Type::staticFun();<br>
+<br>
+ // test calling a void overload of a checked function<br>
+ fun(5);<br>
+<br>
+ // test discarding return value of functions that are not configured to be checked<br>
+ int I = 1;<br>
+ std::launder(&I);<br>
+<br>
+ ns::Type ObjB2;<br>
+ ObjB2.memFun();<br>
+}<br>
<br>
Added: clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp?rev=327833&view=auto" target="_blank">
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp?rev=327833&view=auto</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp (added)<br>
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-unused-return-value.cpp Mon Mar 19 06:02:32 2018<br>
@@ -0,0 +1,166 @@<br>
+// RUN: %check_clang_tidy %s bugprone-unused-return-value %t<br>
+<br>
+namespace std {<br>
+<br>
+struct future {};<br>
+<br>
+enum class launch {<br>
+ async,<br>
+ deferred<br>
+};<br>
+<br>
+template <typename Function, typename... Args><br>
+future async(Function &&, Args &&...);<br>
+<br>
+template <typename Function, typename... Args><br>
+future async(launch, Function &&, Args &&...);<br>
+<br>
+template <typename ForwardIt, typename T><br>
+ForwardIt remove(ForwardIt, ForwardIt, const T &);<br>
+<br>
+template <typename ForwardIt, typename UnaryPredicate><br>
+ForwardIt remove_if(ForwardIt, ForwardIt, UnaryPredicate);<br>
+<br>
+template <typename ForwardIt><br>
+ForwardIt unique(ForwardIt, ForwardIt);<br>
+<br>
+// the check should be able to match std lib calls even if the functions are<br>
+// declared inside inline namespaces<br>
+inline namespace v1 {<br>
+<br>
+template <typename T><br>
+T *launder(T *);<br>
+<br>
+} // namespace v1<br>
+} // namespace std<br>
+<br>
+struct Foo {<br>
+ void f();<br>
+};<br>
+<br>
+int increment(int i) {<br>
+ return i + 1;<br>
+}<br>
+<br>
+void useFuture(const std::future &fut);<br>
+<br>
+void warning() {<br>
+ std::async(increment, 42);<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+<br>
+ std::async(std::launch::async, increment, 42);<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+<br>
+ Foo F;<br>
+ std::launder(&F);<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+<br>
+ std::remove(nullptr, nullptr, 1);<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+<br>
+ std::remove_if(nullptr, nullptr, nullptr);<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+<br>
+ std::unique(nullptr, nullptr);<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+<br>
+ // test discarding return values inside different kinds of statements<br>
+<br>
+ auto Lambda = [] { std::remove(nullptr, nullptr, 1); };<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:22: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+<br>
+ if (true)<br>
+ std::remove(nullptr, nullptr, 1);<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+ else if (true)<br>
+ std::remove(nullptr, nullptr, 1);<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+ else<br>
+ std::remove(nullptr, nullptr, 1);<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+<br>
+ while (true)<br>
+ std::remove(nullptr, nullptr, 1);<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+<br>
+ do<br>
+ std::remove(nullptr, nullptr, 1);<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+ while (true);<br>
+<br>
+ for (;;)<br>
+ std::remove(nullptr, nullptr, 1);<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+<br>
+ for (std::remove(nullptr, nullptr, 1);;)<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:8: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+ ;<br>
+<br>
+ for (;; std::remove(nullptr, nullptr, 1))<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:11: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+ ;<br>
+<br>
+ for (auto C : "foo")<br>
+ std::remove(nullptr, nullptr, 1);<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+<br>
+ switch (1) {<br>
+ case 1:<br>
+ std::remove(nullptr, nullptr, 1);<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+ break;<br>
+ default:<br>
+ std::remove(nullptr, nullptr, 1);<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+ break;<br>
+ }<br>
+<br>
+ try {<br>
+ std::remove(nullptr, nullptr, 1);<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+ } catch (...) {<br>
+ std::remove(nullptr, nullptr, 1);<br>
+ // CHECK-MESSAGES: [[@LINE-1]]:5: warning: the value returned by this function should be used [bugprone-unused-return-value]<br>
+ }<br>
+}<br>
+<br>
+void noWarning() {<br>
+ auto AsyncRetval1 = std::async(increment, 42);<br>
+ auto AsyncRetval2 = std::async(std::launch::async, increment, 42);<br>
+<br>
+ Foo FNoWarning;<br>
+ auto LaunderRetval = std::launder(&FNoWarning);<br>
+<br>
+ auto RemoveRetval = std::remove(nullptr, nullptr, 1);<br>
+<br>
+ auto RemoveIfRetval = std::remove_if(nullptr, nullptr, nullptr);<br>
+<br>
+ auto UniqueRetval = std::unique(nullptr, nullptr);<br>
+<br>
+ // test using the return value in different kinds of expressions<br>
+ useFuture(std::async(increment, 42));<br>
+ std::launder(&FNoWarning)->f();<br>
+ delete std::launder(&FNoWarning);<br>
+<br>
+ if (std::launder(&FNoWarning))<br>
+ ;<br>
+ for (; std::launder(&FNoWarning);)<br>
+ ;<br>
+ while (std::launder(&FNoWarning))<br>
+ ;<br>
+ do<br>
+ ;<br>
+ while (std::launder(&FNoWarning));<br>
+ switch (std::unique(1, 1))<br>
+ ;<br>
+<br>
+ // cast to void should allow ignoring the return value<br>
+ (void)std::async(increment, 42);<br>
+<br>
+ // test discarding return value of functions that are not configured to be checked<br>
+ increment(1);<br>
+<br>
+ // test that the check is disabled inside GNU statement expressions<br>
+ ({ std::async(increment, 42); });<br>
+ auto StmtExprRetval = ({ std::async(increment, 42); });<br>
+}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>