[PATCH] D37014: [clang-tidy] Add a checker to remove useless intermediate variables before return statements with comparisons
Roman Lebedev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 28 11:22:54 PST 2018
lebedev.ri added inline comments.
================
Comment at: test/clang-tidy/readability-unnecessary-intermediate-var.cpp:206
+ auto test = 1; // Test
+#ifdef INTERMITTENT_MACRO
+ return (test == 1);
----------------
tbourvon wrote:
> lebedev.ri wrote:
> > Tests are nice :)
> > But please, add the test with assert-like macro..
> Sorry, I'm not sure I understand what kind of test you are suggesting... Could you give me a short example?
//Something// like this: (did not test at all, just back of the envelope code)
```
void die();
#ifndef NDEBUG
#define assert(cond) void(0) // i.e. it does nothing
#else
#define assert(cond) (cond) ? void(0) : die();
#endif
```
```
bool some_func();
bool f_preprocessor_macro2() {
auto test = some_func();
assert(test); // <- should not be removed regardless of whether NDEBUG is set or not
return test;
}
```
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D37014
More information about the cfe-commits
mailing list