Skip to content

Commit d0afa2f

Browse files
committed
fixed some -Wsuggest-attribute=returns_nonnull GCC warnings
1 parent 0545e65 commit d0afa2f

File tree

9 files changed

+15
-12
lines changed

9 files changed

+15
-12
lines changed

cmake/compileroptions.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
6969
add_compile_options(-Wsuggest-attribute=noreturn)
7070
add_compile_options(-Wno-shadow) # whenever a local variable or type declaration shadows another one
7171
add_compile_options_safe(-Wuseless-cast)
72+
# add_compile_options_safe(-Wsuggest-attribute=returns_nonnull) # reports the warning even if the attribute is set
7273
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
7374
if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 14 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14)
7475
# TODO: verify this regression still exists in clang-15

lib/clangimport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ namespace clangimport {
362362
void addFullScopeNameTokens(TokenList &tokenList, const Scope *recordScope);
363363
Scope *createScope(TokenList &tokenList, Scope::ScopeType scopeType, AstNodePtr astNode, const Token *def);
364364
Scope *createScope(TokenList &tokenList, Scope::ScopeType scopeType, const std::vector<AstNodePtr> &children2, const Token *def);
365-
Token *createTokensCall(TokenList &tokenList);
365+
RET_NONNULL Token *createTokensCall(TokenList &tokenList);
366366
void createTokensFunctionDecl(TokenList &tokenList);
367367
void createTokensForCXXRecord(TokenList &tokenList);
368368
Token *createTokensVarDecl(TokenList &tokenList);

lib/cppcheck.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
116116
* @brief Returns current version number as a string.
117117
* @return version, e.g. "1.38"
118118
*/
119-
static const char * version();
119+
RET_NONNULL static const char * version();
120120

121121
/**
122122
* @brief Returns extra version info as a string.
123123
* This is for returning extra version info, like Git commit id, build
124124
* time/date etc.
125125
* @return extra version info, e.g. "04d42151" (Git commit id).
126126
*/
127-
static const char * extraVersion();
127+
RET_NONNULL static const char * extraVersion();
128128

129129
/**
130130
* @brief Call all "getErrorMessages" in all registered Check classes.

lib/ctu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ namespace CTU {
144144
CPPCHECKLIB std::string getFunctionId(const Tokenizer &tokenizer, const Function *function);
145145

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

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

lib/symboldatabase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ class CPPCHECKLIB Function {
10151015
void isInlineKeyword(bool state) {
10161016
setFlag(fIsInlineKeyword, state);
10171017
}
1018-
const Token *setFlags(const Token *tok1, const Scope *scope);
1018+
RET_NONNULL const Token *setFlags(const Token *tok1, const Scope *scope);
10191019
};
10201020

10211021
class CPPCHECKLIB Scope {
@@ -1440,7 +1440,7 @@ class CPPCHECKLIB SymbolDatabase {
14401440
void debugSymbolDatabase() const;
14411441

14421442
void addClassFunction(Scope *&scope, const Token *&tok, const Token *argStart);
1443-
static Function *addGlobalFunctionDecl(Scope*& scope, const Token* tok, const Token *argStart, const Token* funcStart);
1443+
RET_NONNULL static Function *addGlobalFunctionDecl(Scope*& scope, const Token* tok, const Token *argStart, const Token* funcStart);
14441444
Function *addGlobalFunction(Scope*& scope, const Token*& tok, const Token *argStart, const Token* funcStart);
14451445
void addNewFunction(Scope *&scope, const Token *&tok);
14461446
bool isFunction(const Token *tok, const Scope* outerScope, const Token *&funcStart, const Token *&argStart, const Token*& declEnd) const;

lib/tokenize.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class CPPCHECKLIB Tokenizer {
172172
* '; int *p(0);' => '; int *p = 0;'
173173
*/
174174
void simplifyInitVar();
175-
static Token* initVar(Token* tok);
175+
RET_NONNULL static Token* initVar(Token* tok);
176176

177177
/**
178178
* Simplify the location of "static" and "const" qualifiers in

lib/tokenlist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class CPPCHECKLIB TokenList {
9494
* @param one_line true=>copy all tokens to the same line as dest. false=>copy all tokens to dest while keeping the 'line breaks'
9595
* @return new location of last token copied
9696
*/
97-
static Token *copyTokens(Token *dest, const Token *first, const Token *last, bool one_line = true);
97+
RET_NONNULL static Token *copyTokens(Token *dest, const Token *first, const Token *last, bool one_line = true);
9898

9999
/**
100100
* Create tokens from code.

lib/vfvalue.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,10 @@ namespace ValueFlow
327327

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

330-
static const char* toString(MoveKind moveKind);
331-
static const char* toString(LifetimeKind lifetimeKind);
332-
static const char* toString(LifetimeScope lifetimeScope);
333-
static const char* toString(Bound bound);
330+
RET_NONNULL static const char* toString(MoveKind moveKind);
331+
RET_NONNULL static const char* toString(LifetimeKind lifetimeKind);
332+
RET_NONNULL static const char* toString(LifetimeScope lifetimeScope);
333+
RET_NONNULL static const char* toString(Bound bound);
334334

335335
/** How known is this value */
336336
enum class ValueKind : std::uint8_t {

lib/xml.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "config.h"
2323
#include "path.h"
2424

25+
SUPPRESS_WARNING_GCC_PUSH("-Wsuggest-attribute=returns_nonnull")
2526
SUPPRESS_WARNING_CLANG_PUSH("-Wzero-as-null-pointer-constant")
2627
SUPPRESS_WARNING_CLANG_PUSH("-Wsuggest-destructor-override")
2728
SUPPRESS_WARNING_CLANG_PUSH("-Winconsistent-missing-destructor-override")
@@ -31,6 +32,7 @@ SUPPRESS_WARNING_CLANG_PUSH("-Winconsistent-missing-destructor-override")
3132
SUPPRESS_WARNING_CLANG_POP
3233
SUPPRESS_WARNING_CLANG_POP
3334
SUPPRESS_WARNING_CLANG_POP
35+
SUPPRESS_WARNING_GCC_POP
3436

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

0 commit comments

Comments
 (0)