From 71abd0bd326b97c0617746f8cfb69d9e9e86a492 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 31 Oct 2025 14:15:09 +0100 Subject: [PATCH] added `LIFETIMEBOUND` to `utils.h` and annotated some parameters with it [skip ci] --- cli/cmdlineparser.h | 2 +- cli/executor.h | 4 +++- cli/processexecutor.h | 2 +- cli/singleexecutor.h | 2 +- cli/threadexecutor.h | 2 +- lib/checkersreport.h | 2 +- lib/config.h | 7 +++++++ lib/cppcheck.cpp | 2 +- lib/cppcheck.h | 6 +++--- lib/fwdanalysis.h | 2 +- lib/preprocessor.h | 2 +- lib/programmemory.h | 2 +- lib/symboldatabase.h | 6 +++--- lib/templatesimplifier.h | 2 +- lib/token.h | 2 +- lib/tokenize.h | 2 +- lib/tokenlist.h | 2 +- 17 files changed, 29 insertions(+), 20 deletions(-) diff --git a/cli/cmdlineparser.h b/cli/cmdlineparser.h index 16e9bb56107..9e0564ad467 100644 --- a/cli/cmdlineparser.h +++ b/cli/cmdlineparser.h @@ -55,7 +55,7 @@ class CmdLineParser { * options user has given. * @param suppressions Suppressions instance that keeps the suppressions */ - CmdLineParser(CmdLineLogger &logger, Settings &settings, Suppressions &suppressions); + CmdLineParser(CmdLineLogger &logger LIFETIMEBOUND, Settings &settings LIFETIMEBOUND, Suppressions &suppressions LIFETIMEBOUND); enum class Result : std::uint8_t { Success, Exit, Fail }; diff --git a/cli/executor.h b/cli/executor.h index 3f24b1c9b00..1633d57d0c1 100644 --- a/cli/executor.h +++ b/cli/executor.h @@ -19,6 +19,8 @@ #ifndef EXECUTOR_H #define EXECUTOR_H +#include "config.h" + #include #include #include @@ -41,7 +43,7 @@ class FileWithDetails; */ class Executor { public: - Executor(const std::list &files, const std::list& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger); + Executor(const std::list &files LIFETIMEBOUND, const std::list& fileSettings LIFETIMEBOUND, const Settings &settings LIFETIMEBOUND, Suppressions &suppressions LIFETIMEBOUND, ErrorLogger &errorLogger LIFETIMEBOUND); virtual ~Executor() = default; Executor(const Executor &) = delete; diff --git a/cli/processexecutor.h b/cli/processexecutor.h index 9ed14e6af96..7acd395eb8d 100644 --- a/cli/processexecutor.h +++ b/cli/processexecutor.h @@ -45,7 +45,7 @@ class FileWithDetails; */ class ProcessExecutor : public Executor { public: - ProcessExecutor(const std::list &files, const std::list& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand); + ProcessExecutor(const std::list &files LIFETIMEBOUND, const std::list& fileSettings LIFETIMEBOUND, const Settings &settings LIFETIMEBOUND, Suppressions &suppressions LIFETIMEBOUND, ErrorLogger &errorLogger LIFETIMEBOUND, CppCheck::ExecuteCmdFn executeCommand); ProcessExecutor(const ProcessExecutor &) = delete; ProcessExecutor& operator=(const ProcessExecutor &) = delete; diff --git a/cli/singleexecutor.h b/cli/singleexecutor.h index c2294a2e467..b1801bc48bb 100644 --- a/cli/singleexecutor.h +++ b/cli/singleexecutor.h @@ -33,7 +33,7 @@ class FileWithDetails; class SingleExecutor : public Executor { public: - SingleExecutor(CppCheck &cppcheck, const std::list &files, const std::list& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger); + SingleExecutor(CppCheck &cppcheck, const std::list &files LIFETIMEBOUND, const std::list& fileSettings LIFETIMEBOUND, const Settings &settings LIFETIMEBOUND, Suppressions &suppressions LIFETIMEBOUND, ErrorLogger &errorLogger LIFETIMEBOUND); SingleExecutor(const SingleExecutor &) = delete; SingleExecutor& operator=(const SingleExecutor &) = delete; diff --git a/cli/threadexecutor.h b/cli/threadexecutor.h index 1e6001347d3..e99f64b000c 100644 --- a/cli/threadexecutor.h +++ b/cli/threadexecutor.h @@ -45,7 +45,7 @@ class ThreadExecutor : public Executor { friend class SyncLogForwarder; public: - ThreadExecutor(const std::list &files, const std::list& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand); + ThreadExecutor(const std::list &files LIFETIMEBOUND, const std::list& fileSettings LIFETIMEBOUND, const Settings &settings LIFETIMEBOUND, Suppressions &suppressions LIFETIMEBOUND, ErrorLogger &errorLogger LIFETIMEBOUND, CppCheck::ExecuteCmdFn executeCommand); ThreadExecutor(const ThreadExecutor &) = delete; ThreadExecutor& operator=(const ThreadExecutor &) = delete; diff --git a/lib/checkersreport.h b/lib/checkersreport.h index b189a7f1ebd..48ded055220 100644 --- a/lib/checkersreport.h +++ b/lib/checkersreport.h @@ -28,7 +28,7 @@ class Settings; class CPPCHECKLIB CheckersReport { public: - CheckersReport(const Settings& settings, const std::set& activeCheckers); + CheckersReport(const Settings& settings LIFETIMEBOUND, const std::set& activeCheckers LIFETIMEBOUND); int getActiveCheckersCount(); int getAllCheckersCount(); diff --git a/lib/config.h b/lib/config.h index 34d426eb162..58485fbb3f1 100644 --- a/lib/config.h +++ b/lib/config.h @@ -131,6 +131,13 @@ # define RET_NONNULL #endif +// lifetimebound +#if __has_cpp_attribute (clang::lifetimebound) +# define LIFETIMEBOUND [[clang::lifetimebound]] +#else +# define LIFETIMEBOUND +#endif + #define REQUIRES(msg, ...) class=typename std::enable_if<__VA_ARGS__::value>::type // Use the nonneg macro when you want to assert that a variable/argument is not negative diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 0fb23203718..1916d55412f 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -87,7 +87,7 @@ static const CWE CWE398(398U); // Indicator of Poor Code Quality class CppCheck::CppCheckLogger : public ErrorLogger { public: - CppCheckLogger(ErrorLogger& errorLogger, const Settings& settings, Suppressions& suppressions, bool useGlobalSuppressions) + CppCheckLogger(ErrorLogger& errorLogger LIFETIMEBOUND, const Settings& settings LIFETIMEBOUND, Suppressions& suppressions LIFETIMEBOUND, bool useGlobalSuppressions) : mErrorLogger(errorLogger) , mSettings(settings) , mSuppressions(suppressions) diff --git a/lib/cppcheck.h b/lib/cppcheck.h index 44286c294d2..5156767eda6 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -68,9 +68,9 @@ class CPPCHECKLIB CppCheck { /** * @brief Constructor. */ - CppCheck(const Settings& settings, - Suppressions& supprs, - ErrorLogger &errorLogger, + CppCheck(const Settings& settings LIFETIMEBOUND, + Suppressions& supprs LIFETIMEBOUND, + ErrorLogger &errorLogger LIFETIMEBOUND, bool useGlobalSuppressions, ExecuteCmdFn executeCommand); diff --git a/lib/fwdanalysis.h b/lib/fwdanalysis.h index 389ea195da2..46f344219f2 100644 --- a/lib/fwdanalysis.h +++ b/lib/fwdanalysis.h @@ -38,7 +38,7 @@ class Settings; */ class FwdAnalysis { public: - explicit FwdAnalysis(const Settings &settings) : mSettings(settings) {} + explicit FwdAnalysis(const Settings &settings LIFETIMEBOUND) : mSettings(settings) {} bool hasOperand(const Token *tok, const Token *lhs) const; diff --git a/lib/preprocessor.h b/lib/preprocessor.h index f8f213b13df..e17d4ba9527 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -102,7 +102,7 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor { /** character that is inserted in expanded macros */ static char macroChar; - Preprocessor(simplecpp::TokenList& tokens, const Settings& settings, ErrorLogger &errorLogger, Standards::Language lang); + Preprocessor(simplecpp::TokenList& tokens LIFETIMEBOUND, const Settings& settings LIFETIMEBOUND, ErrorLogger &errorLogger LIFETIMEBOUND, Standards::Language lang); void inlineSuppressions(SuppressionList &suppressions); diff --git a/lib/programmemory.h b/lib/programmemory.h index adb0d1469ce..7f926a0820a 100644 --- a/lib/programmemory.h +++ b/lib/programmemory.h @@ -165,7 +165,7 @@ struct ProgramMemoryState { std::map origins; const Settings& settings; - explicit ProgramMemoryState(const Settings& s); + explicit ProgramMemoryState(const Settings& s LIFETIMEBOUND); void replace(ProgramMemory pm, const Token* origin = nullptr); diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index 954b31cc05b..2741d8ba42e 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -1041,8 +1041,8 @@ class CPPCHECKLIB Scope { const Scope *scope; }; - Scope(const SymbolDatabase &symdb_, const Token *classDef_, const Scope *nestedIn_); - Scope(const SymbolDatabase &symdb_, const Token *classDef_, const Scope *nestedIn_, ScopeType type_, const Token *start_); + Scope(const SymbolDatabase &symdb_ LIFETIMEBOUND, const Token *classDef_, const Scope *nestedIn_); + Scope(const SymbolDatabase &symdb_ LIFETIMEBOUND, const Token *classDef_, const Scope *nestedIn_, ScopeType type_, const Token *start_); const SymbolDatabase& symdb; std::string className; @@ -1338,7 +1338,7 @@ class CPPCHECKLIB ValueType { class CPPCHECKLIB SymbolDatabase { friend class TestSymbolDatabase; public: - explicit SymbolDatabase(Tokenizer& tokenizer); + explicit SymbolDatabase(Tokenizer& tokenizer LIFETIMEBOUND); ~SymbolDatabase(); /** @brief Information about all namespaces/classes/structures */ diff --git a/lib/templatesimplifier.h b/lib/templatesimplifier.h index b5285071841..21fa4411e5b 100644 --- a/lib/templatesimplifier.h +++ b/lib/templatesimplifier.h @@ -46,7 +46,7 @@ struct newInstantiation; /** @brief Simplify templates from the preprocessed and partially simplified code. */ class CPPCHECKLIB TemplateSimplifier { public: - explicit TemplateSimplifier(Tokenizer &tokenizer); + explicit TemplateSimplifier(Tokenizer &tokenizer LIFETIMEBOUND); const std::string& dump() const { return mDump; diff --git a/lib/token.h b/lib/token.h index 5fddf510b19..76dc21c7e59 100644 --- a/lib/token.h +++ b/lib/token.h @@ -202,7 +202,7 @@ class CPPCHECKLIB Token { eNone }; - Token(const TokenList& tokenlist, std::shared_ptr tokensFrontBack); + Token(const TokenList& tokenlist LIFETIMEBOUND, std::shared_ptr tokensFrontBack); // for usage in CheckIO::ArgumentInfo only explicit Token(const Token *tok); ~Token(); diff --git a/lib/tokenize.h b/lib/tokenize.h index 616290e7e2a..1291c4d86f3 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -50,7 +50,7 @@ class CPPCHECKLIB Tokenizer { friend class SymbolDatabase; public: - Tokenizer(TokenList tokenList, ErrorLogger &errorLogger); + Tokenizer(TokenList tokenList, ErrorLogger &errorLogger LIFETIMEBOUND); ~Tokenizer(); void setTimerResults(TimerResults *tr) { diff --git a/lib/tokenlist.h b/lib/tokenlist.h index 764eb67bdee..95dd9ab37ca 100644 --- a/lib/tokenlist.h +++ b/lib/tokenlist.h @@ -50,7 +50,7 @@ struct TokensFrontBack { class CPPCHECKLIB TokenList { public: - explicit TokenList(const Settings& settings, Standards::Language lang); + explicit TokenList(const Settings& settings LIFETIMEBOUND, Standards::Language lang); ~TokenList(); TokenList(const TokenList &) = delete;