Open
Description
https://clang-analyzer.llvm.org/annotations.html#attr_analyzer_noreturn describes the analyzer_noreturn
attribute:
The Clang-specific 'analyzer_noreturn' attribute is almost identical to 'noreturn' except that it is ignored by the compiler for the purposes of code generation.
This attribute is useful for annotating assertion handlers that actually can return, but for the purpose of using the analyzer we want to pretend that such functions do not return.
This attribute is not recognized/supported by some clang-tidy checks, at least the bugprone-unchecked-optional-access
check where I have run into this:
#include <optional>
void myAssertFailedHandler() __attribute__((analyzer_noreturn));
#define MY_ASSERT(EXPR) \
if (!(EXPR)) { \
myAssertFailedHandler(); \
}
void foo(const std::optional<int>& o)
{
MY_ASSERT(o);
// error: unchecked access to optional value [bugprone-unchecked-optional
*o;
}
Changing the attribute to noreturn
will cause the check to pass.
Should clang-tidy's data-flow analysis understand/respect this attribute?