diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 05e9dbe25ac..8ad9408a376 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -20,6 +20,9 @@ jobs: runs-on: ubuntu-22.04 + env: + UNCRUSTIFY_VERSION: 0.80.1 + steps: - uses: actions/checkout@v4 with: @@ -31,17 +34,19 @@ jobs: with: path: | ~/uncrustify - key: ${{ runner.os }}-uncrustify + key: ${{ runner.os }}-uncrustify-${{ env.UNCRUSTIFY_VERSION }} - name: build uncrustify if: steps.cache-uncrustify.outputs.cache-hit != 'true' run: | - wget https://github.com/uncrustify/uncrustify/archive/refs/tags/uncrustify-0.72.0.tar.gz - tar xzvf uncrustify-0.72.0.tar.gz && cd uncrustify-uncrustify-0.72.0 - cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_VERSION_MINIMUM=3.5 + set -x + wget https://github.com/uncrustify/uncrustify/archive/refs/tags/uncrustify-${{ env.UNCRUSTIFY_VERSION }}.tar.gz + tar xzvf uncrustify-${{ env.UNCRUSTIFY_VERSION }}.tar.gz + cd uncrustify-uncrustify-${{ env.UNCRUSTIFY_VERSION }} + cmake -S . -B build -DCMAKE_BUILD_TYPE=Release cmake --build build -- -j$(nproc) -s mkdir ~/uncrustify - cd build && cp uncrustify ~/uncrustify/ + cp build/uncrustify ~/uncrustify/ - name: Uncrustify check run: | diff --git a/.uncrustify.cfg b/.uncrustify.cfg index f15f26a3009..81722ff7249 100644 --- a/.uncrustify.cfg +++ b/.uncrustify.cfg @@ -1,4 +1,4 @@ -# Uncrustify-0.72.0_f +# Uncrustify-0.80.1_f # The original size of tabs in the input. # @@ -133,14 +133,31 @@ indent_class = true # true/false # Default: 1 indent_access_spec = -4 # number -# Whether to collapse empty blocks between '{' and '}'. -# If true, overrides nl_inside_empty_func +# Whether to collapse empty blocks between '{' and '}' except for functions. +# Use nl_collapse_empty_body_functions to specify how empty function braces +# should be formatted. nl_collapse_empty_body = true # true/false +# Whether to collapse empty blocks between '{' and '}' for functions only. +# If true, overrides nl_inside_empty_func. +nl_collapse_empty_body_functions = true # true/false + # Whether to convert all tabs to spaces in comments. If false, tabs in # comments are left alone, unless used for indenting. cmt_convert_tab_to_spaces = true # true/false +# An offset value that controls the indentation of the body of a multiline #define. +# 'body' refers to all the lines of a multiline #define except the first line. +# Requires 'pp_ignore_define_body = false'. +# +# <0: Absolute column: the body indentation starts off at the specified column +# (ex. -3 ==> the body is indented starting from column 3) +# >=0: Relative to the column of the '#' of '#define' +# (ex. 3 ==> the body is indented starting 3 columns at the right of '#') +# +# Default: 8 +pp_multiline_define_body_indent = 4 # number + # The value might be used twice: # - at the assignment # - at the opening brace diff --git a/lib/checkersreport.cpp b/lib/checkersreport.cpp index dd870559936..350ca3bfe6b 100644 --- a/lib/checkersreport.cpp +++ b/lib/checkersreport.cpp @@ -191,11 +191,11 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const const bool cppcheckPremium = isCppcheckPremium(mSettings); auto reportSection = [&fout, cppcheckPremium] - (const std::string& title, - const Settings& settings, - const std::set& activeCheckers, - const std::map& premiumCheckers, - const std::string& substring) { + (const std::string& title, + const Settings& settings, + const std::set& activeCheckers, + const std::map& premiumCheckers, + const std::string& substring) { fout << std::endl << std::endl; fout << title << std::endl; fout << std::string(title.size(), '-') << std::endl; diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index c5962268998..b4e7f0b2b63 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -1502,12 +1502,12 @@ void clangimport::AstNode::createTokensForCXXRecord(TokenList &tokenList) std::vector children2; std::copy_if(children.cbegin(), children.cend(), std::back_inserter(children2), [](const AstNodePtr& child) { return child->nodeType == CXXConstructorDecl || - child->nodeType == CXXDestructorDecl || - child->nodeType == CXXMethodDecl || - child->nodeType == FieldDecl || - child->nodeType == VarDecl || - child->nodeType == AccessSpecDecl || - child->nodeType == TypedefDecl; + child->nodeType == CXXDestructorDecl || + child->nodeType == CXXMethodDecl || + child->nodeType == FieldDecl || + child->nodeType == VarDecl || + child->nodeType == AccessSpecDecl || + child->nodeType == TypedefDecl; }); Scope *scope = createScope(tokenList, isStruct ? ScopeType::eStruct : ScopeType::eClass, children2, classToken); const std::string addr = mExtTokens[0]; diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index de6c9733062..b88511ae72f 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -669,7 +669,7 @@ static ValueFlow::Value evaluate(const std::string& op, const ValueFlow::Value& return result; } -using BuiltinLibraryFunction = std::function&)>; +using BuiltinLibraryFunction = std::function&)>; static std::unordered_map createBuiltinLibraryFunctions() { std::unordered_map functions; diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index cda94aaadb7..95d6b196f8d 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5735,11 +5735,11 @@ static bool hasMatchingConstructor(const Scope* classScope, const ValueType* arg return false; const ValueType* vt = f.getArgumentVar(0)->valueType(); return vt && - vt->type == argType->type && - (argType->sign == ValueType::Sign::UNKNOWN_SIGN || vt->sign == argType->sign) && - vt->pointer == argType->pointer && - (vt->constness & 1) >= (argType->constness & 1) && - (vt->volatileness & 1) >= (argType->volatileness & 1); + vt->type == argType->type && + (argType->sign == ValueType::Sign::UNKNOWN_SIGN || vt->sign == argType->sign) && + vt->pointer == argType->pointer && + (vt->constness & 1) >= (argType->constness & 1) && + (vt->volatileness & 1) >= (argType->volatileness & 1); }); } diff --git a/lib/token.cpp b/lib/token.cpp index 42bad2d08ae..870aae4008a 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -2542,7 +2542,7 @@ bool Token::hasKnownSymbolicValue(const Token* tok) const return mImpl->mValues && std::any_of(mImpl->mValues->begin(), mImpl->mValues->end(), [&](const ValueFlow::Value& value) { return value.isKnown() && value.isSymbolicValue() && value.tokvalue && - value.tokvalue->exprId() == tok->exprId(); + value.tokvalue->exprId() == tok->exprId(); }); } @@ -2615,7 +2615,7 @@ const ValueFlow::Value* Token::getMovedValue() const return nullptr; const auto it = std::find_if(mImpl->mValues->begin(), mImpl->mValues->end(), [](const ValueFlow::Value& value) { return value.isMovedValue() && !value.isImpossible() && - value.moveKind != ValueFlow::Value::MoveKind::NonMovedVariable; + value.moveKind != ValueFlow::Value::MoveKind::NonMovedVariable; }); return it == mImpl->mValues->end() ? nullptr : &*it; } diff --git a/lib/token.h b/lib/token.h index 4298bb1d72a..59774747f70 100644 --- a/lib/token.h +++ b/lib/token.h @@ -1428,7 +1428,7 @@ class CPPCHECKLIB Token { fIsInitBracket = (1ULL << 44), // Is this bracket used as a part of variable initialization i.e: int a{5}, b(2); }; - enum : std::uint8_t { + enum : std::uint8_t { efMaxSize = sizeof(nonneg int) * 8, efIsUnique = efMaxSize - 2, }; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 38c1d207565..ec5354753fc 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10852,10 +10852,10 @@ bool Tokenizer::hasIfdef(const Token *start, const Token *end) const const auto& directives = mDirectives; return std::any_of(directives.cbegin(), directives.cend(), [&](const Directive& d) { return startsWith(d.str, "#if") && - d.linenr >= start->linenr() && - d.linenr <= end->linenr() && - start->fileIndex() < list.getFiles().size() && - d.file == list.getFiles()[start->fileIndex()]; + d.linenr >= start->linenr() && + d.linenr <= end->linenr() && + start->fileIndex() < list.getFiles().size() && + d.file == list.getFiles()[start->fileIndex()]; }); } diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 3ba67c5d081..3201cc1ba03 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2724,7 +2724,7 @@ static void valueFlowLifetimeFunction(Token *tok, const TokenList &tokenlist, Er const Token* varTok = args[iArg - 1]; if (varTok->variable() && varTok->variable()->isLocal()) LifetimeStore{ varTok, "Passed to '" + tok->str() + "'.", ValueFlow::Value::LifetimeKind::Address }.byRef( - tok->next(), tokenlist, errorLogger, settings); + tok->next(), tokenlist, errorLogger, settings); } } } diff --git a/lib/vf_settokenvalue.cpp b/lib/vf_settokenvalue.cpp index ae19abbed8b..b4c2c921559 100644 --- a/lib/vf_settokenvalue.cpp +++ b/lib/vf_settokenvalue.cpp @@ -526,7 +526,7 @@ namespace ValueFlow args2.begin(), [&](const Token* atok, const Token* btok) { return atok->getKnownIntValue() == - btok->getKnownIntValue(); + btok->getKnownIntValue(); }); } else { equal = false;