Hi everyone,
just decided to start playing around with -Wlifetime on Godbolt, and came up with
an example that failed to meet my expectations, namely:
char *leak()
{
return new char;
}
int main()
{
char *ch = leak();
}
Shouldn’t the lifetime static analyser complain that ch on main() leaks, or am I expecting too much from the analyser?
Initially I though that by using main(), the analyser just assumed it would be released anyway, but renaming it to something
else, still doesn’t trigger a leak warning.
Thanks in advance,
Paulo
Hi Paulo,
The -Wlifetime analysis is not part of mainline clang yet (only the statement-local warnings). If you have some questions, concerns regarding the flow-sensitive analysis feel free to open a ticket at https://github.com/mgehre/llvm-project
Currently, the flow-sensitive lifetime analysis does not check for memory leaks. If you want to find leaks statically, you could try out the Clang Static Analyzer (https://clang-analyzer.llvm.org/) which has some great checks to find such issues.
Cheers,
Gabor
Hi Gabor,
thanks for the clarification.
I just got curious after the CppCon talk and wanted to check out the current state.
Cheers,
Paulo