I've been investigating some results of analysis for lxml from openscanhub in Fedora (which uses cppcheck) that seemed false positives and drove me down the cppcheck rabbit hole. I've drafted a simple reproducer that mirrors the generated Cython code that is sprouted from python-lxml and used claude to try to analyze the cause. The issue is a possible null pointer dereference on a line that can never run with a NULL pointer. void f(int *a, int *b) { if (a) *a = 0; else *b = 0; } void g(void) { int...
Just incase someone is using it maybe mark the flag --clang as depricated in the next releaes. Given the amount of work it might make for a good google summer of code project should cppcheck ever want the feature back. I always thought the feature would be more useful for cppcheck internally as away to help debug changes in the c++ standards. I am not sure why someone would use it externally.
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15192
Version: Cppcheck 2.19.0 and 2.22.0 (built from the 2.22.0 tag), Ubuntu 26.04. Code (GCC and Clang compile it with -std=c++11, including an instantiation f<int>()): namespace n { template <typename... Ts> struct S {}; } template <typename... Ts, typename = n::S<decltype(Ts())...>> void f() {} $ cppcheck --language=c++ --std=c++11 h.cpp h.cpp:2:60: error: syntax error [syntaxError] template <typename... Ts, typename = n::S<decltype(Ts())...>> ^ No error when any one of these changes: > > instead of...
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15189
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15188
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15185
Seconded. There hasn't been any activity related to this feature in years.
The clangimport is not working well at all. I get crashes for small simple example C code. This makes me think that it's not used by any users. I do not feel that the ast-dump based approach is a proper approach it was an ugly hack. And I fear also that making the current ast-dump approach work fully would be a lot of work. We should use json if we want to import the clang ast. That would not be so fragile. However a rewrite for json and making it handle C and C++ fully is a really big job. I suggest...
The clangimport is not working well at all. I get crashes for small simple example C code. This makes me think that it's not used by any users. I do not feel that the ast-dump based approach is a proper approach it was an ugly hack. And I fear also that making the current ast-dump approach work fully would be a lot of work. We should use json if we want to import the clang ast. However a rewrite for json and making it handle C and C++ fully is a really big job. I suggest that we remove the clang...
Minimal reproduction: #ifdef KNOWN_MAP_DECLARATION template<typename Key, typename Value> class QMap { public: void insert(const Key&, const Value&); Value value(const Key&) const; }; #else #include <QMap> #endif struct Client { void Update(); }; class Registry { public: void Add(unsigned id, Client* client); void Update(unsigned id) const; private: QMap<unsigned, Client*> Clients; }; void Registry::Add(unsigned id, Client* client) { Clients.insert(id, client); } void Registry::Update(unsigned id)...
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15177
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15173
knownConditionTrueFalse is tracked here: https://trac.cppcheck.net/ticket/15171
Reproduction handler.c: void DefaultHandler(void) { } void (*const Handlers[])(void) = { DefaultHandler }; compare.c: extern void DefaultHandler(void); extern void (*const Handlers[])(void); int HasHandler(int index) { return Handlers[index] != DefaultHandler; } Run both translation units together: cppcheck --enable=all --inline-suppr --template=gcc \ --suppress=checkersReport --suppress=unusedFunction --quiet \ handler.c compare.c Cppcheck 2.22.0 Actual: handler.c:1:6: warning: The function 'DefaultHandler'...
cfg/qt.cfg marks QFile::exists as <pure/>. When the argument is a local const QString, cppcheck reuses the first call's result after a call to an unknown function, and then reports a later identical call as always true. But QFile::exists reads filesystem state, which any unknown call (or another process) can change, so the second result is not known. Either QFile::exists (and probably QFileInfo::exists/QDir::exists) should not be <pure/>, or value flow should drop a pure call's known result after...
uninitMemberVarNoCtor asks for a default member initializer on members of a constructor-less aggregate. Two kinds of member cannot take one: Bit-fields under --std=c++14/c++17: default member initializers for bit-fields only became valid in C++20. Cppcheck warns even with --std=c++14, so the suggested fix does not compile. Flexible array members (char Data[];, GNU/C99 extension common in wire/IPC headers): they have no size, so an initializer is impossible in any standard. A user-written constructor...
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15167
Cppcheck 2.22.0 reports "can be declared as const array" for an array of unsigned char, but not when the element type is a typedef of unsigned char. Reported (expected): static int f(const unsigned char *d, int n); int g(void) { unsigned char a[4] = {0}; return f(a, 4); } constVariable: Variable 'a' can be declared as const array Not reported (false negative): typedef unsigned char u8; static int f(const u8 *d, int n); int g(void) { u8 a[4] = {0}; return f(a, 4); } Command: cppcheck --enable=style...
Hopefully the table below looks ok. I will attach 2 CSV files. The first one is called StatFile.csv and that is this table below. Which shows some stats about code coverage of a few of the CppCheck source code files and all the numbers are %. I checked 4015 Debian packages. I can say the Overall Coverage numbers are under estimates. When I looked at the gcov data I found that it was saying there were 220048 source lines, but going through the output it was counting files outside of cppcheck like...
https://trac.cppcheck.net/ticket/15158 tracks the mismatchingContainersmessage. Having different smart pointers own the same resource is a bug waiting to happen, so I think showing a warning is desirable. Other issues still open.
Looks like a variation of Looks like a variation of https://trac.cppcheck.net/ticket/11562
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15157
Repro Save as value-flow.cpp: #include <cassert> #include <memory> bool DifferentOwners(std::unique_ptr<int>& first, std::unique_ptr<int>& second) { return static_cast<void*>(first.get()) != static_cast<void*>(second.get()); } double UnknownNumber(); void CompareCopiedValue() { const double number = UnknownNumber(); const double copy = number; assert(!(number <= copy)); assert(!(number < copy)); assert(!(number >= copy)); assert(!(number > copy)); } class Label { public: int Height() const; }; class...
I give up. Attached in txt file instead.
...I don't know what keyword is being triggered here for moderation but my post from months ago is still 'awaiting moderation'
...I don't know what keyword is being triggered here for moderation but my last post from months ago is still 'awaiting moderation'
Reproduction #include <cassert> class EventLoop { public: static void ProcessEvents(); }; class Listener { public: bool Start() { Waiting = true; for(int remaining = 2; remaining > 0 && Waiting; --remaining) { EventLoop::ProcessEvents(); } return !Waiting; } void Ready() { Waiting = false; } private: bool Waiting = false; }; Listener* ActiveListener = nullptr; void EventLoop::ProcessEvents() { ActiveListener->Ready(); } int main() { Listener listener; ActiveListener = &listener; const bool started...
For example, when distinct distance and speed constants both equal 1.0. Cppcheck flags their intentional division. Minimal reproduction Save as equal-constants-minimal.cpp: constexpr double DISTANCE_M = 1.0; constexpr double SPEED_MPS = 1.0; double TravelTimeSeconds() { return DISTANCE_M / SPEED_MPS; } Run with Cppcheck 2.22.0: cppcheck --enable=style --std=c++14 --template=gcc equal-constants-minimal.cpp Expected No duplicate-expression diagnostic solely because differently named constants have...
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15154
For the record, these warnings appear when cppcheck only analyzes the header & not the translation unit. So maybe not really a defect but just how it goes...
Minimal reproduction: scratch_functionStatic_callback.h: #pragma once class CallbackReceiver { public: void OnEvent(int) { } }; scratch_functionStatic_callback.cpp: #include "scratch_functionStatic_callback.h" template<typename Receiver> void Register(Receiver* receiver, void (Receiver::*callback)(int)) { (receiver->*callback)(1); } int main() { CallbackReceiver receiver; Register(&receiver, &CallbackReceiver::OnEvent); } Expected Expected: OnEvent remains a non-static member, registration requires...
A fixture retains a non-owning pointer obtained from a local std::unique_ptr. The unique pointer is then moved into a separately implemented owner's constructor, which moves it into a member. The pointee outlives the fixture's creation method, but cppcheck reports that the observer points to a local variable. owner.h: #pragma once #include <memory> class Callback { public: virtual ~Callback() = default; virtual void Invoke() = 0; }; class Owner { public: explicit Owner(std::unique_ptr<Callback> callback);...
Ok I just noticed some of the dates in those PR files I got the packages from. I will remove all the PR files from before Oct 6. Given that is about half of them I will probably add a few more and rerun my code. Hopefully I will see better coverage numbers on the low end. What ever happened to http://cppcheck1.osuosl.org:8000/? When I try to go to the link it says the website can't be reached. I was thinking of pulling the package list from there but the site seems down. I was hoping to also get...
It looks like merged PRs are not flushed out, e.g. https://github.com/cppcheck-opensource/cppcheck/pull/8934
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15126
I also should mention that cppcheck 2.19.0 did not have this false positive.
Hello, We ran into a corner-case false-positive syntaxError I'd like to report. It is similar to this which was fixed long ago. In this corner-case, using the override keyword causes the false positive. struct base { virtual ~base() = default; virtual void foo() try {} catch (...) {}; }; struct special : base { void foo() override // This override causes the try on the next line to false fail. try {} catch (...) {} }; int main() { special s; s.foo(); return 0; } I am testing with cppcheck 2.22.0....
I wrote a couple of bash scripts to run over the weekend to do code coverage of the released 2.22.0 version of cppcheck with debian packages (It's still running). I wasn't sure how you knows a package had C/C++ code in them, so I just pulled from the following 9 PR's below and hopped for the best. 2026-02-18_12-13-45-d234d745fefe-results.txt 2026-10-05_07-31-15-7f232989d1f9-results.txt 2026-10-09_20-01-23-da724f2e5700-results.txt 2026-09-08_13-51-12-2a0c507aec8b-results.txt 2026-10-05_14-59-08-c5bef2ae24cd-results.txt...
I found that cppcheck’s addon dump can produce MISRA diagnostics in a non-source order. In SymbolDatabase::printXml() (lib/symboldatabase.cpp), variables are collected in std::set<const Variable*> before the <variables> XML section is written. This orders records by object-pointer address instead of a stable source key. The MISRA addon reads that XML order into data.variables, and Rule 9.3 then iterates data.variables directly. Therefore Rule 9.3 diagnostics can be reported in a different order from...
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15103
Found in cppcheck 2.22 Running cppcheck --enable=style --std=c++17 --template=gcc repro.cpp on #include <functional> #include <vector> struct Item {}; void example() { Item value; auto& ref = value; std::vector<std::reference_wrapper<Item>> refs{ref}; } gives Variable 'ref' can be declared as reference to const [constVariableReference]
Depending on how many tokens you want to use here are other things you can ask AI about a PR. Will this PR require the cppcheck manual to change? if yes which sections. What unit test cover these changes? if no unit test is found can please write one. What do you think the intent of this PR is?
To me this talk has lived rent free in my brain since 2012 https://youtu.be/5wwKjdvPxa8 its about how CI can be used as a code reviewer. Most CI systems are pass fail. But there tea leaves that often go unnoticed. I think in the age of AI its probably a good idea to use AI as a first pass aproach to keep from getting overwhelmed. I even know of an open source project that is talking internally about poising their skill file to say all issues must be written using Shakespearen English. That way they...
Please provide feedback. Do you think I should tweak the reports or output somehow? Having a link to the actual PR would be nice (instead of/additional to linking to the AWS files). How is reanalysis supposed to work? E.g. for #8918, the latest commit shown is from Oct 5, while there is a newer commit from Oct 7 already (https://github.com/cppcheck-opensource/cppcheck/pull/8918/changes/97161058bc8dbc7b18acf69ae1cf324a21507f65).
I think one thing that matters a lot is how easy is it for you to integrate into your workflow. For me given that I learned to code inside a unix terminal and never evolved to using an IDE to code with AI isnt to difficult to record my interactions with. The script command https://www.redhat.com/en/blog/linux-script-command does alot of the heavy lifting. I also write a bit of data like starting and stopping git hash as well as the ai model version and token usage to a file. That way I can restore...
One thing I recomend when it comes to AI is to keep internal metrics so that you can better help you evluete AI future solutions how do you suggest that I do that?
One thing I recomend when it comes to AI is to keep internal metrics so that you can better help you evluete AI future solutions. That includes keeping track of the work done by AI which you can put a tag in an issue or a tag in the git commit message. You will want to be able to match that tag to a prompt, token usage and model version number. That way if you want to make changes later to your AI process you can test it aginst past solutions to see if the change adds value. On a side note one thing...
Good idea 👍 Having the user name in a column would be nice. Also, some PRs seem to be missing. Are they still being processed?
I am adding AI reviews in opensource cppcheck AI is not perfect there is some bad review comments. As a PR author you can reject such comments by resolving them. My idea going forward is that I will not review a PR manually if there are open AI reviews. I want to limit the amount of manual reviews because; for reviewers it takes a lot of time. I don't want to waste time on nits that we could avoid automatically. I have to re-review the whole PR every time I see some nits. for developers manual reviews...
It's still being processed. If we will have trouble to keep up with open PRs I think we can launch more runner VMs. It might be low with 100/1000 .. I will see if it makes sense to increase these values later. At least if a runner is idle it could fill up more packages..
Good idea 🆙 Having the user name in a column would be nice. Also, some PRs seem to be missing. Are they still being processed?
Good idea 🆙 Having the user name in a column would be nice.
I am experimenting with a webserver that will execute the test-my-pr script on PRs. I want more or less that it will provide daca@home feedback directly when somebody works on a PR. http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/ It is only executed on open non-draft PRs that have a successful CI. It will execute on 1000 packages if the PR modifies tokenizer or valueflow. Otherwise it will execute on 100 packages. When I started it , it would count packages even if they did not have C/C++...
I am experimenting with a webserver that will execute the test-my-pr script on PRs: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/ It will execute on 1000 packages if the PR modifies tokenizer or valueflow. Otherwise it will execute on 100 packages. When I started it , it would count packages even if they did not have C/C++ code that is fixed now.. AI-generated verdicts will be provided for a random subset of the warnings (up to 20 or so). Those should be taken with a grain of salt for...
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15089
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15088
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15087
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15086
I see a false positive running cppcheck 2.22.0 against the following code. Note the parameter cannot be declared as reference to const because its job is to match both const and mutable references, and return a reference to a member which retains the const-ness of the first argument (similar to the 'deduce this' pattern). The static asserts demonstrate the intended use cases. Note also that the false positive goes away if the concept is inlined as a template requires clause on the function itself...
I see a false positive running cppcheck 2.22.0 against the following code. Note the function itself cannot be static because it's an explicit member function (deducing this). #include <array> #include <cstddef> #include <ranges> #include <span> constexpr std::size_t GridSize{19}; class board { public: auto rows(this auto&& self) { auto* cells = self.data.data(); return std::views::iota(0zu, GridSize) | std::views::transform([cells](std::size_t row) { return std::span{cells + row * GridSize, GridSize};...
We've had this issue for many releases so can't provide a version that it started Running cppcheck --std=c++20 --enable=style,warning --template=gcc repro.cpp on namespace Legacy { struct Base { int Count() const; virtual void Print() const; virtual ~Base() = default; }; struct Position : Base { }; } using namespace Legacy; namespace Modern { struct Position { int Count() const; void Print() const; }; } gives repro.cpp:21:7: warning: The struct 'Position' defines member function with name 'Count'...
We've had this issue for many releases so can't provide a version that it started Running cppcheck --std=c++20 --enable=style,warning --template=gcc repro.cpp on namespace Legacy { struct Base { int Count() const; virtual void Print() const; virtual ~Base() = default; }; struct Position : Base { }; } using namespace Legacy; namespace Modern { struct Position { int Count() const; void Print() const; }; } gives repro.cpp:21:7: warning: The struct 'Position' defines member function with name 'Count'...
Reduced: struct S { bool f() const; int g() const; int x, y; }; bool S::f() const { const bool b = x ? g() < 0 : 0 > y; return b; }
Came in when upgrading from 2.21 to 2.22 Running cppcheck --std=c++20 --template=gcc on #include <algorithm> #include <vector> struct Box { float xMin, yMin, xMax, yMax; float Height() const { return yMax - yMin; } }; struct Processor { std::vector<Box> Update(const std::vector<Box>& input, int begin, int end) const; }; std::vector<Box> Processor::Update(const std::vector<Box>& input, int begin, int end) const { std::vector<Box> output; const auto visit = [&](int first, int last) { for (const auto&...
Came in when upgrading from 2.21 to 2.22 Running cppcheck --std=c++20 --template=gcc on #include <algorithm> #include <vector> struct Box { float xMin, yMin, xMax, yMax; float Height() const { return yMax - yMin; } }; struct Processor { std::vector<Box> Update(const std::vector<Box>& input, int begin, int end) const; }; std::vector<Box> Processor::Update(const std::vector<Box>& input, int begin, int end) const { std::vector<Box> output; const auto visit = [&](int first, int last) { for (const auto&...
Came in when upgrading from 2.21 to 2.22 Running cppcheck --std=c++20 --template=gcc --error-exitcode=2 repro.cpp on #include <algorithm> #include <vector> struct Box { float xMin, yMin, xMax, yMax; float Height() const { return yMax - yMin; } }; struct Processor { std::vector<Box> Update(const std::vector<Box>& input, int begin, int end) const; }; std::vector<Box> Processor::Update(const std::vector<Box>& input, int begin, int end) const { std::vector<Box> output; const auto visit = [&](int first,...
Came in when upgrading from 2.21 to 2.22 Running cppcheck --std=c++20 --template=gcc --error-exitcode=2 repro.cpp on #include <algorithm> #include <vector> struct Box { float xMin, yMin, xMax, yMax; float Height() const { return yMax - yMin; } }; struct Processor { std::vector<Box> Update(const std::vector<Box>& input, int begin, int end) const; }; std::vector<Box> Processor::Update(const std::vector<Box>& input, int begin, int end) const { std::vector<Box> output; const auto visit = [&](int first,...
i got this error and point to first { open braces when i use this code in my sources cppcheck run this check from myproject.cppcheck but i have no any error when i check this file or dir with my sources
i got this error and point to first { open braces when i use this code in my sources cppcheck run this check from myproject.cppcheck but i have no any error when i just this file
i got this error and point to { open braces when i use this code in my sources cppcheck run this check from myproject.cppcheck but i have no any error when i just this file
Hello, I found a preprocessing cache issue and have prepared a fix and regression test locally. Could a team member please create a Trac ticket so I can reference it in a pull request? Issue With --cppcheck-build-dir, unchanged input can be analyzed again on the immediate second run because the preprocessing hash depends on header load order. I reproduced this on commit fa6c1f1327057cb8ad4764df236daf6d3c70e359, using Windows x64 and an MSVC 2022 Debug build. Minimal reproduction Create these three...
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15076
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15075
See https://trac.cppcheck.net/ticket/14677
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15074
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15073
Looks like a special case of https://trac.cppcheck.net/ticket/1606
See https://trac.cppcheck.net/ticket/9921 and others.
See https://trac.cppcheck.net/ticket/2853
See https://trac.cppcheck.net/ticket/10201
Hi, I found a false negative regarding the rule arrayIndexOutOfBounds. Cppcheck misses an out-of-bounds write when the array is accessed through a pointer alias. int a[2]; void f() { int *p = a; p[2] = 0; } Actual result Cppcheck does not report arrayIndexOutOfBounds. Replacing p[2] = 0 with a[2] = 0 produces the warning. Expected result Cppcheck should report the out-of-bounds write through the alias. Verification The issue was reproduced with: cppcheck --output-format=xmlv2 --enable=all array_alias.cpp...
Hi, I found a false negative regarding the rule arrayIndexOutOfBounds. Cppcheck misses an out-of-bounds write when the array expression is written as the address of its first element. int a[2]; void f() { (&a[0])[2] = 0; } Actual result Cppcheck does not report arrayIndexOutOfBounds. Replacing (&a[0])[2] = 0 with a[2] = 0 produces the warning. The form ((int *)a)[2] = 0 is also missed. Expected result Cppcheck should report the out-of-bounds write in these equivalent subscript forms. Verification...
Hi, I found a false negative regarding the rule resourceLeak. Cppcheck misses the resource leak when the null check uses a local alias of the file pointer. #include <cstdio> int f() { const FILE *a = fopen("input.txt", "r"); const FILE *b = a; if (!b) return 0; return 0; } Actual result Cppcheck does not report resourceLeak. Removing b and changing the condition to if (!a) produces the warning. Expected result Cppcheck should report the missing fclose in both forms. Verification The issue was reproduced...
Hi, I found a false negative regarding the rule memleak. Cppcheck misses the leak when the allocated buffer is accessed through a pointer-to-pointer alias. #include <stdlib.h> int f(void) { int result = 0; char *a = malloc(10); char **b = &a; if (*b) { (*b)[0] = 0; result = (*b)[0]; } return result; } Actual result Cppcheck does not report memleak. Removing b and replacing each *b access with a produces the warning. Expected result Cppcheck should report the missing free in both forms. Verification...
Hi, I found a false negative regarding the rule invalidContainer. Cppcheck misses the use of an invalidated iterator when the vector is accessed through a reference alias. #include <vector> void f() { std::vector<int> items{1, 2, 3}; std::vector<int> &values = items; auto iter = values.begin(); values.erase(iter); ++iter; } Actual result Cppcheck does not report invalidContainer. Removing the reference declaration and replacing values with items produces the warning. Expected result Cppcheck should...
Hi, I found a false negative regarding the rule invalidContainer. Cppcheck misses the use of an invalidated vector iterator when the increment is written as an explicit operator call. #include <vector> void f() { std::vector<int> items{1, 2, 3}; std::vector<int>::iterator iter; for (iter = items.begin(); iter != items.end(); iter.operator++()) { if (*iter == 2) items.erase(iter); } } Actual result Cppcheck does not report invalidContainer. Replacing iter.operator++() with ++iter produces the warning....
Hi, I found a false negative regarding the rule autoVariables. Cppcheck misses an escaping local address when it passes through a pointer temporary. void f(int **out) { int local = 1; int *temporary = &local; *out = temporary; } Actual result Cppcheck does not report autoVariables. Replacing the last two statements with *out = &local; produces the warning. Expected result Cppcheck should report that the address of the local variable is assigned through the output parameter in both forms. Verification...
Hi, I found a false negative regarding the rule arrayIndexOutOfBounds. Cppcheck misses an out-of-bounds write when array indexing is written as pointer arithmetic. int a[2]; void f() { *(a + 2) = 0; } Actual result Cppcheck does not report arrayIndexOutOfBounds. Replacing *(a + 2) = 0 with a[2] = 0 produces the warning. Expected result Cppcheck should report the out-of-bounds write in both forms. Verification The issue was reproduced with: cppcheck --output-format=xmlv2 --enable=all array_pointer.cpp...
Hi, I found a false negative regarding the rule AssignmentAddressToInteger. Cppcheck misses the pointer-to-integer conversion when it is written as a compound assignment. int f(int *p) { int a = 0; a += p; return a + 4; } Actual result Cppcheck does not report AssignmentAddressToInteger. Replacing a += p with a = a + p produces the warning. Expected result Cppcheck should also report the pointer-to-integer conversion in the compound assignment. Verification The issue was reproduced with: cppcheck...
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15070
The syntaxError comes from Tokenizer::findGarbageCode. (line numbers from eb4b6526b3502ee779a74019f814d45d890427ba) Breakpoint 1.1, Tokenizer::syntaxError (this=0x7fffffffc550, tok=0x555556240920, code="") at /home/tsteven4/work/cppcheck/lib/tokenize.cpp:8441 8441 { (gdb) bt #0 Tokenizer::syntaxError (this=0x7fffffffc550, tok=0x555556240920, code="") at /home/tsteven4/work/cppcheck/lib/tokenize.cpp:8441 #1 0x00005555556f183f in Tokenizer::findGarbageCode (this=0x7fffffffc550) at /home/tsteven4/work/cppcheck/lib/tokenize.cpp:9113...
cppcheck reports a false positive syntaxError on c++20 bitfields that contain both a size and a brace initializer, which were allowed in c++20. A test case below includes sizes from more complex integral constant expressions, but handling the simple case "int m5:5{55};" would allow the most common usage to proceed in cppcheck. I reproduced this with 2.19.0 on ubuntu 26.04, but it also fails with main@eb4b6526b3502ee779a74019f814d45d890427ba cppcheck --enable=all --std=c++20 test.cc Checking test.cc...
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15061
Added here: https://trac.cppcheck.net/ticket/11563
The false negative with visible function definition looks similar to https://trac.cppcheck.net/ticket/14804
Added here: https://trac.cppcheck.net/ticket/15058
I don't get a syntaxError with latest head.
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15059
Hi, I found a false negative in Cppcheck 2.21.0 when a boolean comparison result is multiplied into the divisor. Affected tool Cppcheck 2.21.0 Affected checker Cppcheck CheckOther::checkZeroDivision (zerodiv / zerodivcond) Minimal reproducer int divide_by_boolean_product(int x, int y) { int divisor = (x < 0) * y; return 1 / divisor; } Reproduction command cppcheck --version cppcheck --enable=warning --std=c11 --checkers-report=checkers.txt --template='{file}:{line}:{column}: [{id}] {message}' cppcheck-zerodiv-fn-boolean-product.c...