From 71bb73399eea5c8d6227a1fa9ca7fa1d6187fac4 Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Wed, 1 Jan 2025 20:21:46 +0100 Subject: [PATCH] std.cfg: Added support for std::clamp() --- cfg/std.cfg | 24 +++++++++++++++++++++++- test/cfg/std.cpp | 19 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/cfg/std.cfg b/cfg/std.cfg index 3cb938bf6b8..5762090bd88 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -69,7 +69,7 @@ true - + true @@ -6363,6 +6363,28 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun + + + + + + false + + + arg1<arg2?arg2:arg1>arg3?arg3:arg1 + + + + + + + + + + + + + diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index b613e630252..1595e7b21b5 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -73,6 +73,25 @@ void unreachableCode_std_unexpected(int &x) } #endif +#ifdef __cpp_lib_clamp +int ignoredReturnValue_std_clamp(const int x) +{ + // cppcheck-suppress ignoredReturnValue + std::clamp(x, 1, -1); + return std::clamp(x, 1, -1); +} +void knownConditionTrueFalse_std_clamp(const int x) +{ + // cppcheck-suppress knownConditionTrueFalse + if(std::clamp(-2, -1, 1) == -1){} + // cppcheck-suppress knownConditionTrueFalse + if(std::clamp(2, -1, 1) == 1){} + // cppcheck-suppress knownConditionTrueFalse + if(std::clamp(0, -1, 1) == 0){} + if(std::clamp(x, 0, 2)){} +} +#endif // __cpp_lib_clamp + void unreachableCode_std_terminate(int &x) { std::terminate();