-
Notifications
You must be signed in to change notification settings - Fork 13.2k
The misc-static-assert check warns on assert(false) in some configurations. #23254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The cause of the warning is not the different implementation of assert but bool's. The checker reports cases when the false / zero literal is from a macro expansion e.g. assert(sys::IsLittleEndianHost && "Unexpected host endianness"). |
Handling macros 'false', 'FALSE', 'False' seems reasonable. Not sure about "zero" though. Did you see them being used somewhere? |
It was just an idea but now I think zero shouldn't be included in the exceptions since I didn't found it used as an assert condition. |
I'll reuse the bug instead of closing it: there's one more case where the check complains on assert(false)/assert(0): void abort() {} void f() { |
*** Bug llvm/llvm-bugzilla-archive#23355 has been marked as a duplicate of this bug. *** |
Friendly ping. Szabolcs, are you going to have time to tackle this? |
We use the pretty common idiom of switch (something) { e.g. in case()s that ought not to be reached. misc-static-assert tags these as "replaceable with static_assert", which of course they're not, being run-time dependent on the 'something'. This seems to be a manifestation of the same bug here? |
Re: |
One more problem: it complains on the code like this: #define ASAN_REGION_IS_POISONED(addr, size) (0) |
Bumped into same issue. We use our own assert macro and following cases trigger warning: #define IM_ASSERT(_COND) assert(_COND) IM_ASSERT(0); |
mentioned in issue llvm/llvm-bugzilla-archive#23355 |
1 similar comment
mentioned in issue llvm/llvm-bugzilla-archive#23355 |
@rokups Have you found a workaround for your example? We have a similar usage that you have described. |
Probably not. It was a long while ago, i do not remember for sure, sorry |
Original issue looks to be fixed by 43a298c. |
Extended Description
I've come up with a short repro, however it seems to depend on the standard library implementation and compiler options, so I've manually partially preprocessed the input to remove external dependencies:
$ cat test.cc
// A specific implementation of <stdbool.h>.
#define bool _Bool
#define true 1
#define false 0
#define __bool_true_false_are_defined 1
// A specific implementation of <assert.h>
extern void __assert_fail(const char *__assertion, const char *__file,
unsigned int __line, const char *__function)
attribute((noreturn));
#define assert(expr)
((expr) ? (void)(0)
: __assert_fail(#expr, FILE, LINE, ((const char *)0)))
void f() {
assert(false);
}
$ ~/work/llvm-build/bin/clang-tidy -checks=-,misc- test.cc -- -std=gnu++11
1 warning generated.
test.cc:20:3: warning: found assert() that could be replaced by static_assert() [misc-static-assert]
assert(false);
^
static_assert , ""
The text was updated successfully, but these errors were encountered: