Came in when upgrading from 2.21 to 2.22
Running cppcheck --std=c++20 --template=gcc on
cppcheck --std=c++20 --template=gcc
#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& item : input) { const auto current = Box{item.xMin, item.yMin, item.xMax, item.yMax}; auto previous = std::find_if(output.begin(), output.end(), [&](const Box& box) { return box.xMin == current.xMin; }); if (previous != output.end()) { const float right = last - current.xMax; const float left = current.xMin - first; const float previousRight = last - previous->xMax; const float previousLeft = previous->xMin - first; const bool replace = (right == previousRight && left == previousLeft) ? previous->Height() < current.Height() : std::min(previousLeft, previousRight) > std::min(left, right); if (!replace) continue; *previous = current; } output.push_back(current); } }; visit(begin, end); return output; }
gives
repro.cpp:31:32: warning: syntax error [syntaxError] ? previous->Height() < current.Height() ^
A workaround is to put brackets around it
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; }
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15086
Log in to post a comment.
Came in when upgrading from 2.21 to 2.22
Running
cppcheck --std=c++20 --template=gccon
gives
A workaround is to put brackets around it
Last edit: Dan Workman 2026-10-02
Reduced:
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15086