[PATCH] D41655: [clang-tidy] New check bugprone-unused-return-value
Kalle Huttunen via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 8 10:56:28 PST 2018
khuttun added inline comments.
================
Comment at: test/clang-tidy/bugprone-unused-return-value.cpp:163
+
+void noWarning() {
+ auto AsyncRetval1 = std::async(increment, 42);
----------------
aaron.ballman wrote:
> khuttun wrote:
> > aaron.ballman wrote:
> > > khuttun wrote:
> > > > aaron.ballman wrote:
> > > > > Sorry, I just realized that we're missing a test case for a common situation -- where the result is used as part of another call expression. Can you add a test to `noWarning()` to make sure this does not warn:
> > > > > ```
> > > > > std::vector<int> v;
> > > > > extern void f(bool);
> > > > >
> > > > > f(v.empty()); // Should not warn
> > > > > ```
> > > > See line 199 in this file.
> > > Ah, my eyes missed that, thank you!
> > >
> > > Hmm, I *think* this test should also be okay, but I want to be sure:
> > > ```
> > > std::vector<int> v;
> > > bool b = ({v.empty()}); // Should not warn
> > > ({v.empty()}); // ???
> > > ```
> > > I kind of thing that, as an extension to the spirit of this check, any GNU expression statement whose result is unused should probably be diagnosed; what do you think?
> > >
> > > You should add tests for the above so we document the expected behavior here.
> > Getting a warning when just surrounding the call expression with parenthesis is tested in bugprone-unused-return-value-custom.cpp.
> >
> > Would your example be parsed as creating an initializer_list? In that case it should not warn. I can add test cases for that.
> >
> > What do you mean by "GNU expression"?
> > Getting a warning when just surrounding the call expression with parenthesis is tested in bugprone-unused-return-value-custom.cpp.
>
> Yup, this is something entirely different, however.
>
> > Would your example be parsed as creating an initializer_list? In that case it should not warn. I can add test cases for that.
> >
> > What do you mean by "GNU expression"?
>
> Those examples are GNU expression statements, which is a GCC extension that Clang also supports. See https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html for more information.
>
> Effectively, the last statement in the GNU expression statement is the "return value" of the expression statement. We should make sure the warnings are sensible with this construct.
This was a good catch. Code like this
```
auto Gnu = ({ fun(); });
```
is currently causing a warning.
https://reviews.llvm.org/D41655
More information about the cfe-commits
mailing list