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

Improve support for std::priority_queue, std::tie #5871

Merged
merged 6 commits into from
Jan 11, 2024
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
23 changes: 17 additions & 6 deletions cfg/std.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6642,7 +6642,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<!-- void std::stack::push( value_type&& value ); // since C++11 -->
<!-- void std::vector::push_back( const T& value ); -->
<!-- void std::vector::push_back( T&& value ); // since C++11 -->
<function name="std::deque::push_back,std::deque::push_front,std::list::push_back,std::list::push_front,std::forward_list::push_front,std::queue::push,std::stack::push,std::vector::push_back">
<function name="std::deque::push_back,std::deque::push_front,std::list::push_back,std::list::push_front,std::forward_list::push_front,std::queue::push,std::priority_queue::push,std::stack::push,std::vector::push_back">
<noreturn>false</noreturn>
<returnValue type="void"/>
<arg nr="1">
Expand Down Expand Up @@ -6678,7 +6678,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<not-uninit/>
</arg>
</function>
<function name="std::deque::emplace_back,std::deque::emplace_front,std::list::emplace_back,std::list::emplace_front,std::forward_list::emplace_front,std::queue::emplace,std::stack::emplace,std::vector::emplace_back,std::vector::emplace_front,std::unordered_set::emplace">
<function name="std::deque::emplace_back,std::deque::emplace_front,std::list::emplace_back,std::list::emplace_front,std::forward_list::emplace_front,std::queue::emplace,std::priority_queue::emplace,std::stack::emplace,std::vector::emplace_back,std::vector::emplace_front,std::unordered_set::emplace">
<noreturn>false</noreturn>
<arg nr="variadic">
<not-uninit/>
Expand Down Expand Up @@ -6811,10 +6811,10 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<arg nr="1">
</arg>
</function>
<function name="std::stack::pop,std::queue::pop">
<function name="std::stack::pop,std::queue::pop,std::priority_queue::pop">
<noreturn>false</noreturn>
</function>
<function name="std::stack::top">
<function name="std::stack::top,std::priority_queue::top">
<use-retval/>
<noreturn>false</noreturn>
</function>
Expand Down Expand Up @@ -8587,6 +8587,17 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
<noreturn>false</noreturn>
<returnValue type="void *"/>
</function>
<function name="std::tie">
<noreturn>false</noreturn>
<use-retval/>
<arg nr="variadic">
</arg>
</function>
<function name="std::exception::what,std::logic_error::what,std::invalid_argument::what,std::domain_error::what,std::length_error::what,std::out_of_range::what,std::future_error::what,std::runtime_error::what,std::range_error::what,std::overflow_error::what,std::underflow_error::what,std::regex_error::what,std::system_error::what,std::ios_base::failure::what,std::filesystem::filesystem_error::what,std::nonexistent_local_time::what,std::ambiguous_local_time::what,std::format_error::what,std::bad_typeid::what,std::bad_cast::what,std::bad_any_cast::what,std::bad_optional_access::what,std::bad_expected_access::what,std::bad_weak_ptr::what,std::bad_function_call::what,std::bad_alloc::what,std::bad_array_new_length::what,std::bad_exception::what,std::ios_base::failure::what,std::bad_variant_access::what">
<noreturn>false</noreturn>
<use-retval/>
<returnValue type="const char *"/>
</function>
<memory>
<alloc init="false" buffer-size="malloc">malloc</alloc>
<alloc init="true" buffer-size="calloc">calloc</alloc>
Expand Down Expand Up @@ -8675,7 +8686,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
<size templateParameter="0"/>
<access indexOperator="array-like"/>
</container>
<container id="stdQueue" startPattern="std :: queue|priority_queue &lt;" inherits="stdContainer">
<container id="stdQueue" startPattern="std :: queue &lt;" inherits="stdContainer">
<access>
<function name="emplace" action="push" yields="item"/>
<function name="push" action="push"/>
Expand All @@ -8684,7 +8695,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
<function name="back" yields="item"/>
</access>
</container>
<container id="stdStack" startPattern="std :: stack &lt;" inherits="stdContainer">
<container id="stdStack" startPattern="std :: stack|priority_queue &lt;" inherits="stdContainer">
<access>
<function name="emplace" action="push" yields="item"/>
<function name="push" action="push"/>
Expand Down
32 changes: 32 additions & 0 deletions test/cfg/std.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define __STDC_WANT_LIB_EXT1__ 1
#include <ctime>
#include <cwchar>
#include <exception>
#include <fstream>
#include <functional>
#ifndef __STDC_NO_THREADS__
Expand All @@ -38,7 +39,10 @@
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string_view>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
Expand Down Expand Up @@ -899,6 +903,34 @@ int std_map_find_constref(std::map<int, int>& m) // #11857
return ++*p;
}

void std_queue_front_ignoredReturnValue(const std::queue<int>& q) {
// cppcheck-suppress ignoredReturnValue
q.front();
}

void std_priority_queue_top_ignoredReturnValue(const std::priority_queue<int>& pq) {
// cppcheck-suppress ignoredReturnValue
pq.top();
}

void std_tie_ignoredReturnValue(int a, int b)
{
std::set<int> s;
std::set<int>::iterator it;
bool success;
std::tie(it, success) = s.insert(1);
// cppcheck-suppress ignoredReturnValue
std::tie();
// cppcheck-suppress ignoredReturnValue
std::tie(a, b);
}

void std_exception_ignoredReturnValue(const std::exception& e)
{
// cppcheck-suppress ignoredReturnValue
e.what();
}

void valid_code()
{
std::vector<int> vecInt{0, 1, 2};
Expand Down
Loading