Skip to content

Commit

Permalink
fixed some -Wsuggest-attribute=returns_nonnull GCC warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Oct 23, 2024
1 parent 0545e65 commit d0afa2f
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions cmake/compileroptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wsuggest-attribute=noreturn)
add_compile_options(-Wno-shadow) # whenever a local variable or type declaration shadows another one
add_compile_options_safe(-Wuseless-cast)
# add_compile_options_safe(-Wsuggest-attribute=returns_nonnull) # reports the warning even if the attribute is set
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 14 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14)
# TODO: verify this regression still exists in clang-15
Expand Down
2 changes: 1 addition & 1 deletion lib/clangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ namespace clangimport {
void addFullScopeNameTokens(TokenList &tokenList, const Scope *recordScope);
Scope *createScope(TokenList &tokenList, Scope::ScopeType scopeType, AstNodePtr astNode, const Token *def);
Scope *createScope(TokenList &tokenList, Scope::ScopeType scopeType, const std::vector<AstNodePtr> &children2, const Token *def);
Token *createTokensCall(TokenList &tokenList);
RET_NONNULL Token *createTokensCall(TokenList &tokenList);
void createTokensFunctionDecl(TokenList &tokenList);
void createTokensForCXXRecord(TokenList &tokenList);
Token *createTokensVarDecl(TokenList &tokenList);
Expand Down
4 changes: 2 additions & 2 deletions lib/cppcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
* @brief Returns current version number as a string.
* @return version, e.g. "1.38"
*/
static const char * version();
RET_NONNULL static const char * version();

/**
* @brief Returns extra version info as a string.
* This is for returning extra version info, like Git commit id, build
* time/date etc.
* @return extra version info, e.g. "04d42151" (Git commit id).
*/
static const char * extraVersion();
RET_NONNULL static const char * extraVersion();

/**
* @brief Call all "getErrorMessages" in all registered Check classes.
Expand Down
2 changes: 1 addition & 1 deletion lib/ctu.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace CTU {
CPPCHECKLIB std::string getFunctionId(const Tokenizer &tokenizer, const Function *function);

/** @brief Parse current TU and extract file info */
CPPCHECKLIB FileInfo *getFileInfo(const Tokenizer &tokenizer);
CPPCHECKLIB RET_NONNULL FileInfo *getFileInfo(const Tokenizer &tokenizer);

CPPCHECKLIB std::list<FileInfo::UnsafeUsage> getUnsafeUsage(const Tokenizer &tokenizer, const Settings &settings, bool (*isUnsafeUsage)(const Settings &settings, const Token *argtok, MathLib::bigint *value));

Expand Down
4 changes: 2 additions & 2 deletions lib/symboldatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ class CPPCHECKLIB Function {
void isInlineKeyword(bool state) {
setFlag(fIsInlineKeyword, state);
}
const Token *setFlags(const Token *tok1, const Scope *scope);
RET_NONNULL const Token *setFlags(const Token *tok1, const Scope *scope);
};

class CPPCHECKLIB Scope {
Expand Down Expand Up @@ -1440,7 +1440,7 @@ class CPPCHECKLIB SymbolDatabase {
void debugSymbolDatabase() const;

void addClassFunction(Scope *&scope, const Token *&tok, const Token *argStart);
static Function *addGlobalFunctionDecl(Scope*& scope, const Token* tok, const Token *argStart, const Token* funcStart);
RET_NONNULL static Function *addGlobalFunctionDecl(Scope*& scope, const Token* tok, const Token *argStart, const Token* funcStart);
Function *addGlobalFunction(Scope*& scope, const Token*& tok, const Token *argStart, const Token* funcStart);
void addNewFunction(Scope *&scope, const Token *&tok);
bool isFunction(const Token *tok, const Scope* outerScope, const Token *&funcStart, const Token *&argStart, const Token*& declEnd) const;
Expand Down
2 changes: 1 addition & 1 deletion lib/tokenize.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class CPPCHECKLIB Tokenizer {
* '; int *p(0);' => '; int *p = 0;'
*/
void simplifyInitVar();
static Token* initVar(Token* tok);
RET_NONNULL static Token* initVar(Token* tok);

/**
* Simplify the location of "static" and "const" qualifiers in
Expand Down
2 changes: 1 addition & 1 deletion lib/tokenlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class CPPCHECKLIB TokenList {
* @param one_line true=>copy all tokens to the same line as dest. false=>copy all tokens to dest while keeping the 'line breaks'
* @return new location of last token copied
*/
static Token *copyTokens(Token *dest, const Token *first, const Token *last, bool one_line = true);
RET_NONNULL static Token *copyTokens(Token *dest, const Token *first, const Token *last, bool one_line = true);

/**
* Create tokens from code.
Expand Down
8 changes: 4 additions & 4 deletions lib/vfvalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ namespace ValueFlow

enum class LifetimeScope : std::uint8_t { Local, Argument, SubFunction, ThisPointer, ThisValue } lifetimeScope = LifetimeScope::Local;

static const char* toString(MoveKind moveKind);
static const char* toString(LifetimeKind lifetimeKind);
static const char* toString(LifetimeScope lifetimeScope);
static const char* toString(Bound bound);
RET_NONNULL static const char* toString(MoveKind moveKind);
RET_NONNULL static const char* toString(LifetimeKind lifetimeKind);
RET_NONNULL static const char* toString(LifetimeScope lifetimeScope);
RET_NONNULL static const char* toString(Bound bound);

/** How known is this value */
enum class ValueKind : std::uint8_t {
Expand Down
2 changes: 2 additions & 0 deletions lib/xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "config.h"
#include "path.h"

SUPPRESS_WARNING_GCC_PUSH("-Wsuggest-attribute=returns_nonnull")
SUPPRESS_WARNING_CLANG_PUSH("-Wzero-as-null-pointer-constant")
SUPPRESS_WARNING_CLANG_PUSH("-Wsuggest-destructor-override")
SUPPRESS_WARNING_CLANG_PUSH("-Winconsistent-missing-destructor-override")
Expand All @@ -31,6 +32,7 @@ SUPPRESS_WARNING_CLANG_PUSH("-Winconsistent-missing-destructor-override")
SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_CLANG_POP
SUPPRESS_WARNING_GCC_POP

inline static tinyxml2::XMLError xml_LoadFile(tinyxml2::XMLDocument& doc, const char* filename)
{
Expand Down

0 comments on commit d0afa2f

Please sign in to comment.