From 9a2b8959535a4b2eeaf10e3b21e57a65c2260e50 Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 11 Jan 2024 12:53:43 +0100 Subject: [PATCH 1/6] Improve support for std::priority_queue --- cfg/std.cfg | 12 ++++++------ test/cfg/std.cpp | 11 +++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cfg/std.cfg b/cfg/std.cfg index b32b4cae74a..82f084ec40f 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -6642,7 +6642,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun - + false @@ -6678,7 +6678,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun - + false @@ -6811,10 +6811,10 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun - + false - + false @@ -8675,7 +8675,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init - + @@ -8684,7 +8684,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init - + diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 28279b77a6f..38bcb2759f5 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -899,6 +900,16 @@ int std_map_find_constref(std::map& m) // #11857 return ++*p; } +void std_queue_front_ignoredReturnValue(const std::queue& q) { + // cppcheck-suppress ignoredReturnValue + q.front(); +} + +void std_priority_queue_top_ignoredReturnValue(const std::priority_queue& pq) { + // cppcheck-suppress ignoredReturnValue + pq.top(); +} + void valid_code() { std::vector vecInt{0, 1, 2}; From 071e5c6ad7fa52a391b8104a3ad757af11447901 Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 11 Jan 2024 13:04:53 +0100 Subject: [PATCH 2/6] Fix test --- test/cfg/std.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 38bcb2759f5..aa3529e4146 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -900,12 +900,12 @@ int std_map_find_constref(std::map& m) // #11857 return ++*p; } -void std_queue_front_ignoredReturnValue(const std::queue& q) { +void std_queue_front_ignoredReturnValue(const std::queue& q) { // cppcheck-suppress ignoredReturnValue q.front(); } -void std_priority_queue_top_ignoredReturnValue(const std::priority_queue& pq) { +void std_priority_queue_top_ignoredReturnValue(const std::priority_queue& pq) { // cppcheck-suppress ignoredReturnValue pq.top(); } From 54697a49e2d519ab9f31d2f52f49e1da570bdd66 Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 11 Jan 2024 17:15:44 +0100 Subject: [PATCH 3/6] Add support for std::tie --- cfg/std.cfg | 6 ++++++ test/cfg/std.cpp | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/cfg/std.cfg b/cfg/std.cfg index 82f084ec40f..edb76a1e4e8 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -8587,6 +8587,12 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init false + + false + + + + malloc calloc diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index aa3529e4146..11ad186eb7b 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -910,6 +910,18 @@ void std_priority_queue_top_ignoredReturnValue(const std::priority_queue& p pq.top(); } +void std_tie_ignoredReturnValue(int a, int b) +{ + std::set s; + std::set::iterator it; + bool b; + std::tie(it, b) = s.insert(1); + // cppcheck-suppress ignoredReturnValue + std::tie(); + // cppcheck-suppress ignoredReturnValue + std::tie(a, b); +} + void valid_code() { std::vector vecInt{0, 1, 2}; From e9b0f1953fdb7e7f2c132ccf440db79fa3c873c6 Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 11 Jan 2024 17:17:23 +0100 Subject: [PATCH 4/6] Fix --- test/cfg/std.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 11ad186eb7b..5a5e5a52a2d 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -39,7 +39,9 @@ #include #include #include +#include #include +#include #include #include #include From 6837e8f7a6a391b8faf0e39ed49b3520610242f5 Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 11 Jan 2024 17:28:35 +0100 Subject: [PATCH 5/6] Fix --- test/cfg/std.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 5a5e5a52a2d..d48817a7f31 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -916,8 +916,8 @@ void std_tie_ignoredReturnValue(int a, int b) { std::set s; std::set::iterator it; - bool b; - std::tie(it, b) = s.insert(1); + bool success; + std::tie(it, success) = s.insert(1); // cppcheck-suppress ignoredReturnValue std::tie(); // cppcheck-suppress ignoredReturnValue From 06a14f8fb57d47710380c85a060e0215e7e32d22 Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 11 Jan 2024 19:46:10 +0100 Subject: [PATCH 6/6] Add support for std::exception::what etc. --- cfg/std.cfg | 5 +++++ test/cfg/std.cpp | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/cfg/std.cfg b/cfg/std.cfg index edb76a1e4e8..753cd006ae1 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -8593,6 +8593,11 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init + + false + + + malloc calloc diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index d48817a7f31..1d2c17e8de6 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -25,6 +25,7 @@ #define __STDC_WANT_LIB_EXT1__ 1 #include #include +#include #include #include #ifndef __STDC_NO_THREADS__ @@ -924,6 +925,12 @@ void std_tie_ignoredReturnValue(int a, int b) std::tie(a, b); } +void std_exception_ignoredReturnValue(const std::exception& e) +{ + // cppcheck-suppress ignoredReturnValue + e.what(); +} + void valid_code() { std::vector vecInt{0, 1, 2};