-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
fixed some -Wsuggest-attribute=returns_nonnull
GCC warnings
#6950
Conversation
779c985
to
9985936
Compare
I manually checked all the function usages and in almost all cases we already used them like they were returning a non-null result. |
I also filed llvm/llvm-project#106392 upstream about detecting the unnecessary checks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that clang/gcc will ensure that the functions do NOT return null if it's marked with that attribute? Otherwise removing the safety checks would look dangerous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm it does not seem that clang/gcc warns properly when pointer could be NULL:
daniel@laptop:~/cppchecksolutions/cppcheck$ g++ -fsyntax-only -Wall -Wextra -pedantic 1.cpp
daniel@laptop:~/cppchecksolutions/cppcheck$ clang++ -fsyntax-only -Weverything 1.cpp
1.cpp:2:39: warning: no previous prototype for function 'p' [-Wmissing-prototypes]
__attribute__((returns_nonnull)) int* p(int*p) {
^
1.cpp:2:34: note: declare 'static' if the function is not intended to be used outside of this translation unit
__attribute__((returns_nonnull)) int* p(int*p) {
^
static
1 warning generated.
daniel@laptop:~/cppchecksolutions/cppcheck$ cat 1.cpp
__attribute__((returns_nonnull)) int* p(int*p) {
if (!p) {}
return p;
}
So it would be a bad idea to remove the safety checks that checks the return value?
There is an upcoming static analyzer check: llvm/llvm-project@4f33e7c.
The checks we remove should not change much - if we do not want that then we need to add 100+ checks to the code. |
We could also detect it ourselves: https://trac.cppcheck.net/ticket/13048. Enabling the Clang Static Analyzer is looked at in #6835. |
9985936
to
2ee9352
Compare
No further comments in over a month - merging. |
No description provided.