summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/warn-unused-result.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Refactor the way we handle diagnosing unused expression results.Aaron Ballman2019-01-041-0/+40
| | | | | | | | Rather than sprinkle calls to DiagnoseUnusedExprResult() around in places where we want diagnostics, we now diagnose unused expression statements and full expressions in a more generic way when acting on the final expression statement. This results in more appropriate diagnostics for [[nodiscard]] where we were previously lacking them, such as when the body of a for loop is not a compound statement. This patch fixes PR39837. llvm-svn: 350404
* Corrrect warn_unused_result attribute Erich Keane2017-04-191-0/+46
| | | | | | | | | | | | The original idea was that if the attribute on an operator, that the return-value unused-ness wouldn't matter. However, all of the operators except postfix inc/dec return references! References don't result in this warning anyway, so those are already excluded. Differential Revision: https://reviews.llvm.org/D32207 llvm-svn: 300764
* Properly implement warn_unused_result checking for classes/structs.Kaelyn Takata2015-04-091-2/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous implementation would copy the attribute from the class to functions that have the class as their return type when the functions are first declared. This proved to have two flaws: 1) if the class is forward-declared without the attribute and a function or method with the class as a its return type is declared, and afterward the class is defined with warn_unused_result, the function or method would never inherit the attribute, and 2) the check simply failed for functions and methods that are part of a template instantiation, regardless of whether the class with warn_unused_result is part of a specific instantiation or part of the template itself (presumably because those function/method declaration does not hit the same code path as a non-template one and so never inherits the attribute). The new approach is to instead modify the two places where a function or method call is checked for the warn_unused_result attribute on the decl by extending the checks to also look for the attribute on the decl's return type. Additionally, the check for return types that have the warn_unused_result now excludes pointers and references to such types, as such return types do not necessarily imply a transfer of ownership for the underlying object being referred to by the return value. This does not change the behavior of functions that are directly given the warn_unused_result attribute. llvm-svn: 234526
* Adding a -Wunused-value warning for expressions with side effects used in an ↵Aaron Ballman2014-12-171-1/+1
| | | | | | unevaluated expression context, such as sizeof(), or decltype(). Also adds a similar warning when the expression passed to typeid() *is* evaluated, since it is equally likely that the user would expect the expression operand to be unevaluated in that case. llvm-svn: 224465
* No longer emit diagnostics about unused results (comparisons, etc) from ↵Aaron Ballman2014-10-161-0/+47
| | | | | | unevaluated contexts. Fixes PR18571. llvm-svn: 219954
* Sema: Simplify the check if a method returns an instance of the class.Benjamin Kramer2013-10-161-0/+16
| | | | | | | Just checking if the parent of the method is the same as the return type should be sufficient. Also fixes PR17587. llvm-svn: 192802
* For classes that have the warn_unused_result attribute, don't apply theKaelyn Uhrain2012-11-131-0/+6
| | | | | | | attribute to the class' methods even when they return an instance of the class (e.g. assignment operators). llvm-svn: 167873
* A couple of small fixes to r167783Kaelyn Uhrain2012-11-131-1/+1
| | | | llvm-svn: 167791
* Enable C++11 attribute syntax for warn_unused_result and allow it to beKaelyn Uhrain2012-11-121-1/+31
| | | | | | | | | | | | | applied to CXXRecordDecls, where functions with that return type will inherit the warn_unused_result attribute. Also includes a tiny fix (with no discernable behavior change for existing code) to re-sync AttributeDeclKind enum and err_attribute_wrong_decl_type with warn_attribute_wrong_decl_type since the enum is used with both diagnostic messages to chose the correct description. llvm-svn: 167783
* Clean up the tests for warning about unused function results given theChandler Carruth2011-02-211-0/+44
appropriate attribute. Add a bit more testing that finds a pretty bad regression (since ~forever) in this warning. Fix it with a nice 2 line change. =] llvm-svn: 126098
OpenPOWER on IntegriCloud