Skip to content

Commit 9dbbd03

Browse files
authored
Merge branch 'main' into main
2 parents 7774c9d + df67f2b commit 9dbbd03

30 files changed

Lines changed: 1231 additions & 151 deletions

cfg/gtk.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<define name="G_LIKELY(expr)" value="(expr)"/>
9393
<define name="G_UNLIKELY(expr)" value="(expr)"/>
9494
<define name="G_DEPRECATED" value="__attribute__((__deprecated__))"/>
95+
<define name="G_DEPRECATED_FOR(f)" value="__attribute__((__deprecated__(&quot;Use '&quot; #f &quot;' instead&quot;)))"/>
9596
<define name="G_STMT_START" value="do"/>
9697
<define name="G_STMT_END" value="while (0)"/>
9798
<define name="_G_TYPE_CIC(ip, gt, ct)" value="((ct*) ip)"/>
@@ -126,6 +127,7 @@
126127
<define name="g_try_new(struct_type, n_structs)" value="_G_NEW (struct_type, n_structs, try_malloc)"/>
127128
<define name="g_try_new0(struct_type, n_structs)" value="_G_NEW (struct_type, n_structs, try_malloc0)"/>
128129
<define name="g_try_renew(struct_type, mem, n_structs)" value="_G_RENEW (struct_type, mem, n_structs, try_realloc)"/>
130+
<define name="G_ENCODE_VERSION(major, minor)" value="((major) &lt;&lt; 16 | (minor) &lt;&lt; 8)"/>
129131
<define name="GTK_BUTTON(obj)" value="((GtkButton*)(obj))"/>
130132
<define name="GTK_BOX(obj)" value="((GtkBox*)(obj))"/>
131133
<define name="GTK_CONTAINER(obj)" value="((GtkContainer*)(obj))"/>

cmake/compilerDefinitions.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ endif()
2020
if ((USE_LIBCXX AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
2121
if(CPPCHK_GLIBCXX_DEBUG AND CMAKE_BUILD_TYPE STREQUAL "Debug")
2222
# TODO: determine proper version for AppleClang - current value is based on the oldest version avaialble in CI
23-
if((CMAKE_CXX_COMPILER_ID STREQUALS "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18) OR
23+
if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18) OR
2424
(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 17))
2525
add_definitions(-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG)
2626
else()

lib/astutils.cpp

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,23 +2226,18 @@ static bool isEscapedOrJump(const Token* tok, bool functionsScope, const Library
22262226
return Token::Match(tok, "return|goto|throw|continue|break");
22272227
}
22282228

2229+
static bool isNoreturnFunction(const Token* ftok, const Library& library)
2230+
{
2231+
if (const Function* function = ftok->function())
2232+
return function->isEscapeFunction() || function->isAttributeNoreturn();
2233+
return library.isnoreturn(ftok);
2234+
}
2235+
22292236
bool isEscapeFunction(const Token* ftok, const Library& library)
22302237
{
22312238
if (!Token::Match(ftok, "%name% ("))
22322239
return false;
2233-
if (Token::Match(ftok, "exit|abort"))
2234-
return true;
2235-
const Function* function = ftok->function();
2236-
if (function) {
2237-
if (function->isEscapeFunction())
2238-
return true;
2239-
if (function->isAttributeNoreturn())
2240-
return true;
2241-
} else {
2242-
if (library.isnoreturn(ftok))
2243-
return true;
2244-
}
2245-
return false;
2240+
return isNoreturnFunction(ftok, library);
22462241
}
22472242

22482243
static bool hasNoreturnFunction(const Token* tok, const Library& library, const Token** unknownFunc)
@@ -2253,18 +2248,9 @@ static bool hasNoreturnFunction(const Token* tok, const Library& library, const
22532248
while (Token::simpleMatch(ftok, "("))
22542249
ftok = ftok->astOperand1();
22552250
if (ftok) {
2256-
const Function * function = ftok->function();
2257-
if (function) {
2258-
if (function->isEscapeFunction())
2259-
return true;
2260-
if (function->isAttributeNoreturn())
2261-
return true;
2262-
} else if (library.isnoreturn(ftok)) {
2263-
return true;
2264-
} else if (Token::Match(ftok, "exit|abort")) {
2251+
if (isNoreturnFunction(ftok, library))
22652252
return true;
2266-
}
2267-
if (unknownFunc && !function && library.functions().count(library.getFunctionName(ftok)) == 0)
2253+
if (unknownFunc && !ftok->function() && library.functions().count(library.getFunctionName(ftok)) == 0)
22682254
*unknownFunc = ftok;
22692255
return false;
22702256
}

lib/checkers.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ namespace checkers {
167167
{"CheckSizeof::sizeofVoid","portability"},
168168
{"CheckSizeof::sizeofsizeof","warning"},
169169
{"CheckSizeof::suspiciousSizeofCalculation","warning,inconclusive"},
170+
{"CheckStl::algorithmOutOfBounds",""},
170171
{"CheckStl::checkDereferenceInvalidIterator","warning"},
171172
{"CheckStl::checkDereferenceInvalidIterator2",""},
172173
{"CheckStl::checkFindInsert","performance"},

lib/checkother.cpp

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ void CheckOtherImpl::redundantAssignmentSameValueError(const Token *tok, const V
791791
//---------------------------------------------------------------------------
792792
static inline bool isFunctionOrBreakPattern(const Token *tok)
793793
{
794-
return Token::Match(tok, "%name% (") || Token::Match(tok, "break|continue|return|exit|goto|throw");
794+
return Token::Match(tok, "%name% (") || (tok->isKeyword() && Token::Match(tok, "break|continue|return|goto|throw"));
795795
}
796796

797797
void CheckOtherImpl::redundantBitwiseOperationInSwitchError()
@@ -2323,18 +2323,12 @@ static bool isConstStatement(const Token *tok, const Library& library, bool plat
23232323

23242324
static bool isVoidStmt(const Token *tok)
23252325
{
2326-
if (Token::simpleMatch(tok, "( void"))
2326+
if (Token::simpleMatch(tok, "( void") && !(tok->astOperand1() && (tok->astOperand1()->isLiteral() || isNullOperand(tok->astOperand1()))))
23272327
return true;
2328-
if (isCPPCast(tok) && tok->astOperand1() && Token::Match(tok->astOperand1()->next(), "< void *| >"))
2328+
if (isCPPCast(tok) && tok->astOperand1() && Token::Match(tok->astOperand1()->next(), "< void *| >") &&
2329+
!(tok->astOperand2() && (tok->astOperand2()->isLiteral() || isNullOperand(tok->astOperand2()))))
23292330
return true;
2330-
const Token *tok2 = tok;
2331-
while (tok2->astOperand1())
2332-
tok2 = tok2->astOperand1();
2333-
if (Token::simpleMatch(tok2->previous(), ")") && Token::simpleMatch(tok2->linkAt(-1), "( void"))
2334-
return true;
2335-
if (Token::simpleMatch(tok2, "( void"))
2336-
return true;
2337-
return Token::Match(tok2->previous(), "delete|throw|return");
2331+
return false;
23382332
}
23392333

23402334
static bool isConstTop(const Token *tok)
@@ -2425,37 +2419,31 @@ void CheckOtherImpl::checkIncompleteStatement()
24252419

24262420
void CheckOtherImpl::constStatementError(const Token *tok, const std::string &type, bool inconclusive)
24272421
{
2428-
const Token *valueTok = tok;
2429-
while (valueTok && valueTok->isCast())
2430-
valueTok = valueTok->astOperand2() ? valueTok->astOperand2() : valueTok->astOperand1();
2431-
24322422
std::string msg;
24332423
if (Token::simpleMatch(tok, "=="))
24342424
msg = "Found suspicious equality comparison. Did you intend to assign a value instead?";
24352425
else if (Token::Match(tok, ",|!|~|%cop%"))
24362426
msg = "Found suspicious operator '" + tok->str() + "', result is not used.";
24372427
else if (Token::Match(tok, "%var%"))
24382428
msg = "Unused variable value '" + tok->str() + "'";
2439-
else if (isConstant(valueTok)) {
2429+
else if (isConstant(tok)) {
24402430
std::string typeStr("string");
2441-
if (valueTok->isNumber())
2431+
if (tok->isNumber())
24422432
typeStr = "numeric";
2443-
else if (valueTok->isBoolean())
2433+
else if (tok->isBoolean())
24442434
typeStr = "bool";
2445-
else if (valueTok->tokType() == Token::eChar)
2435+
else if (tok->tokType() == Token::eChar)
24462436
typeStr = "character";
2447-
else if (isNullOperand(valueTok))
2448-
typeStr = "NULL";
2449-
else if (valueTok->isEnumerator())
2437+
else if (isNullOperand(tok))
2438+
typeStr = "null";
2439+
else if (tok->isEnumerator())
24502440
typeStr = "enumerator";
24512441
msg = "Redundant code: Found a statement that begins with " + typeStr + " constant.";
24522442
}
24532443
else if (!tok)
24542444
msg = "Redundant code: Found a statement that begins with " + type + " constant.";
2455-
else if (tok->isCast() && tok->tokType() == Token::Type::eExtendedOp) {
2456-
msg = "Redundant code: Found unused cast ";
2457-
msg += valueTok ? "of expression '" + valueTok->expressionString() + "'." : "expression.";
2458-
}
2445+
else if (tok->isCast() && tok->tokType() == Token::Type::eExtendedOp)
2446+
msg = "Redundant code: Found unused cast in expression '" + tok->expressionString() + "'.";
24592447
else if (tok->str() == "?" && tok->tokType() == Token::Type::eExtendedOp)
24602448
msg = "Redundant code: Found unused result of ternary operator.";
24612449
else if (tok->str() == "." && tok->tokType() == Token::Type::eOther)
@@ -4153,7 +4141,8 @@ static const Token *findShadowed(const Scope *scope, const Variable& var, int li
41534141
return v.nameToken();
41544142
}
41554143
auto it = std::find_if(scope->functionList.cbegin(), scope->functionList.cend(), [&](const Function& f) {
4156-
return f.type == FunctionType::eFunction && f.name() == var.name() && precedes(f.tokenDef, var.nameToken());
4144+
return f.type == FunctionType::eFunction && f.name() == var.name()
4145+
&& (scope->isClassOrStructOrUnion() || precedes(f.tokenDef, var.nameToken()));
41574146
});
41584147
if (it != scope->functionList.end())
41594148
return it->tokenDef;

0 commit comments

Comments
 (0)