Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.cfg: Added support for std::clamp() #7154

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion cfg/std.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<noreturn>true</noreturn>
</function>
<!-- void unexpected(); (until C++11) -->
<!-- [[noreturn]] void unexpected(); (since C++11) -->
<!-- [[noreturn]] void unexpected(); (since C++11) -->
<!-- (deprecated)(removed in C++17) -->
<function name="std::unexpected">
<noreturn>true</noreturn>
Expand Down Expand Up @@ -6363,6 +6363,28 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<arg nr="1" direction="in"/>
<leak-ignore/>
</function>
<!-- template< class T > constexpr const T& std::clamp( const T& v, const T& lo, const T& hi); (since C++17) -->
<!-- template< class T, class Compare > constexpr const T& std::clamp( const T& v, const T& lo, const T& hi, Compare comp ); (since C++17) -->
<!-- https://en.cppreference.com/w/cpp/algorithm/clamp -->
<function name="clamp,std::clamp">
<use-retval/>
<noreturn>false</noreturn>
<leak-ignore/>
<pure/>
<returnValue>arg1&lt;arg2?arg2:arg1&gt;arg3?arg3:arg1</returnValue>
<arg nr="1" direction="in">
<not-uninit/>
</arg>
<arg nr="2" direction="in">
<not-uninit/>
</arg>
<arg nr="3" direction="in">
<not-uninit/>
</arg>
<arg nr="4" direction="in" default="">
<not-uninit/>
</arg>
</function>
<!-- template <class T> const T& min(const T& a, const T& b); -->
<function name="min,std::min">
<use-retval/>
Expand Down
19 changes: 19 additions & 0 deletions test/cfg/std.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading