-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Closed
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-negativeWarning doesn't fire when it shouldWarning doesn't fire when it shouldgood first issuehttps://github.com/llvm/llvm-project/contributehttps://github.com/llvm/llvm-project/contribute
Description
The following pattern is often used to evaluate an expensive function only once, cache its result, and return that on subsequent calls.
int foo() {
static bool is_true = [](){ return expensive_helper_function; };
return is_true;
}
But this code is subtly wrong. It should be
static bool is_true = [](){ return expensive_helper_function; }(); // Note the parens!
In the bad case it looks as though the lambda is being evaluated to a pointer(?) and this is being evaluated always to true
when it is assigned to is_true
.
It feels as though -Wpointer-bool-conversion
should flag this, but it does not (godbolt).
Metadata
Metadata
Assignees
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-negativeWarning doesn't fire when it shouldWarning doesn't fire when it shouldgood first issuehttps://github.com/llvm/llvm-project/contributehttps://github.com/llvm/llvm-project/contribute