Repository navigation
Gecode 7: clang-tidy sweep - #274
Merged
Merged
Conversation
zayenz
force-pushed
the
feature/breaking-7
branch
4 times, most recently
from
November 7, 2026 08:04
08405b4 to
bb0af29
Compare
zayenz
force-pushed
the
feature/breaking-7
branch
from
November 20, 2026 09:39
bb0af29 to
58e3488
Compare
zayenz
changed the base branch from
main
to
feature/breaking-7-10-scoped-enums
November 20, 2026 09:39
This was referenced Nov 20, 2026
zayenz
force-pushed
the
feature/breaking-7
branch
from
November 24, 2026 16:59
58e3488 to
71d71b1
Compare
|
Important Review skippedToo many files! This PR contains 1036 files, which is 736 over the limit of 300. To get a review, reduce the PR to 300 files or fewer by splitting it into smaller PRs or changing its base branch. Usage-priced reviews support at most 500 files.
|
zayenz
force-pushed
the
feature/breaking-7
branch
from
November 25, 2026 21:35
71d71b1 to
230288b
Compare
zayenz
force-pushed
the
feature/breaking-7
branch
from
November 25, 2026 21:54
230288b to
7b5b02e
Compare
zayenz
force-pushed
the
feature/breaking-7
branch
from
November 26, 2026 19:14
0658682 to
c0087f6
Compare
zayenz
force-pushed
the
feature/breaking-7
branch
5 times, most recently
from
November 27, 2026 20:31
970238a to
082e7d7
Compare
zayenz
marked this pull request as ready for review
November 30, 2026 13:08
zayenz
force-pushed
the
feature/breaking-7
branch
from
November 30, 2026 13:24
082e7d7 to
8bc440d
Compare
zayenz
force-pushed
the
feature/breaking-7
branch
4 times, most recently
from
December 1, 2026 14:14
2374484 to
2ed8b34
Compare
zayenz
force-pushed
the
feature/breaking-7
branch
from
December 1, 2026 16:11
2ed8b34 to
c0b49fa
Compare
Empty parameter lists are now (), and modernize-redundant-void-arg keeps them
so. Behaviour and casts to void are unchanged. clang-tidy covers what this
platform compiles; a byte-level pass covers the rest, and generated files
follow their inputs.
Reproduce this commit by running the following at the root of a Git tree of
the parent commit:
set -euo pipefail
llvm=/opt/homebrew/opt/llvm@22/bin
export PATH="$llvm:/opt/homebrew/opt/bison/bin:/opt/homebrew/opt/flex/bin:$PATH"
export CLANG_FORMAT="$llvm/clang-format" CLANG_TIDY="$llvm/clang-tidy"
root=$(pwd -P)
build=build/void-args
rm -rf "$build"
cmake -S . -B "$build" -G Ninja -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DGECODE_ENABLE_EXPERIMENTAL=ON \
-DGECODE_ENABLE_CBS=ON -DGECODE_ENABLE_CPPROFILER=ON \
-DGECODE_ENABLE_FAULT_INJECTION=ON -DGECODE_ENABLE_AUDIT=ON \
-DGECODE_ENABLE_GIST=ON -DGECODE_ENABLE_QT=ON
run-clang-tidy -clang-tidy-binary "$CLANG_TIDY" -p "$build" -j 10 -quiet \
-checks='-*,modernize-redundant-void-arg' -warnings-as-errors='-*' \
-extra-arg=-UNDEBUG -fix \
-header-filter "$root/(gecode|test|examples|tools)/" \
-exclude-header-filter '/gecode/flatzinc/(parser\.tab\.(cpp|hpp)|lexer\.yy\.cpp)$' \
-source-filter "^$root/(?!gecode/flatzinc/(parser\.tab\.cpp|lexer\.yy\.cpp)$)(gecode|test|examples|tools)/" \
> "$build/clang-tidy.log" 2>&1
python3 - <<'PY'
import pathlib
import re
code = {".hpp", ".cpp", ".hh", ".yxx", ".lxx"}
generated = {"parser.tab.cpp", "parser.tab.hpp", "lexer.yy.cpp"}
files = [path for top in ("gecode", "test", "examples", "tools")
for path in pathlib.Path(top).rglob("*")
if path.suffix in code and path.name not in generated
and "third-party" not in path.parts]
files += [*pathlib.Path(".github/ci").glob("*.sh"), *pathlib.Path(".github/ci").glob("*.ps1"),
pathlib.Path("misc/genvarimp.py")]
before = re.compile(rb"[\w)\]}>+\-*/=!<&|^~%][ \t]*$")
keyword = re.compile(rb"\b(?:return|else|do|sizeof|alignof|typeid|decltype|noexcept)[ \t]*$")
gap = re.compile(rb"(?:\s+|//[^\n]*\n|/\*.*?\*/)*", re.S)
after = re.compile(rb"[;{:=,)>&#]|->|(?:const|volatile|noexcept|override|final|throw|try)\b|$")
def replace(match):
text = match.string
head = text[max(match.start() - 40, 0):match.start()]
tail = gap.match(text, match.end()).end()
is_list = before.search(head) and not keyword.search(head) and after.match(text, tail)
return b"()" if is_list else match[0]
for path in sorted(files):
source = path.read_bytes()
result = re.sub(rb"\(void\)", replace, source)
if result != source:
path.write_bytes(result)
PY
python3 - <<'PY'
import pathlib
def replace(name, old, new):
path = pathlib.Path(name)
text = path.read_text()
assert text.count(old) == 1, old
path.write_text(text.replace(old, new))
replace(".clang-tidy", " modernize-deprecated-headers,\n",
" modernize-deprecated-headers,\n modernize-redundant-void-arg,\n")
replace("docs/code-style.md", "## Checking changes\n", """\
An empty parameter list is `()`, also in function pointer types and
`std::function` signatures. `(void)` is a C spelling and stays only in C
sources, where it means something different.
`modernize-redundant-void-arg` enforces the rule. A cast to `void` that discards
a value, such as `(void)new (p) T()`, is a different construct and stays.
`forceinline` stays lowercase, although it is a macro, so that it reads like
`inline`.
""")
replace("docs/breaking-7.md", "- Revisit the `forceinline` portability macro and obsolete `(void)` parameter lists.\n", "")
replace("docs/breaking-7.md", " compatibility aliases; see `code-style.md`.\n", """\
compatibility aliases; see `code-style.md`.
- Empty parameter lists are `()`, and `forceinline` keeps its lowercase name;
see `code-style.md`.
""")
PY
cmake --build "$build" --target regenerate
uv run misc/check.py format
Zdev-Change-Id: Z9b69e8fd20237843076a34a448f17e293c9f0ebb980e71dbe776ea78776d21f8
zayenz
force-pushed
the
feature/breaking-7
branch
from
December 1, 2026 16:31
c0b49fa to
fe46b74
Compare
Enable the bugprone, concurrency, misc, modernize, performance, portability, and readability groups as a whole, excluding each check that still reports something, so later commits either remove an exclusion together with its fixes or keep it as a decision. This commit removes the bugprone and misc exclusions that fit: - bugprone-incorrect-roundings: the TSP distances round with llround, since adding 0.5 before truncating is wrong for values just below a half. - bugprone-unhandled-self-assignment: NaryInter and NaryUnion dropped their free list when assigned to themselves. TaskArray's copy members only copied their fields and are now defaulted. - misc-unconventional-assign-operator: assignment operators return T& to *this; those returning a const reference or a converted base result change. - bugprone-crtp-constructor-accessibility: SparseTupleState and BlockClient can only be constructed by the class they were written for. - misc-override-with-different-visibility: SteelMillBranch inherited from Brancher privately by accident. - misc-redundant-expression: the variable header generator wrote x ^ x into the modification event tables and now writes 0. - misc-misplaced-const: const Tuple made the pointer const, not the tuple. - misc-anonymous-namespace-in-header: Cumulatives uses std::less instead of a local class; the example instance files keep theirs, since one example includes each. - bugprone-exception-escape, without main and the move members: the three remaining reports are marked as false positives. - bugprone-reserved-identifier allows _GNU_SOURCE, which the blackbox backend must define for glibc. bugprone-empty-catch accepts a block whose comment says the exception is expected or ignored. bugprone-parent-virtual-call marks the deliberate grandparent calls in set LDSB. - bugprone-nondeterministic-pointer-iteration-order, bugprone-bitwise-pointer-cast (std::copy_n for region heap blocks), bugprone-suspicious-string-compare, bugprone-assignment-in-if-condition, and misc-definitions-in-headers need small local fixes. The integer literal actions in lexer.lxx move off the rule line, which readability-misleading-indentation reported in the generated lexer.
Remove the readability exclusions that fit, with their fixes: else-after-return, simplify-boolean-expr without De Morgan rewrites, inconsistent-declaration-parameter-name (with the Doxygen parameter references), container-size-empty, container-contains, redundant-casting, use-concise-preprocessor-directives, static-accessed-through-instance, redundant-member-init, redundant-parentheses, redundant-string-init, const-return-type, avoid-const-params-in-decls, container-data-pointer, redundant-control-flow, uppercase-literal-suffix, qualified-auto, redundant-smartptr-get, use-std-min-max, avoid-return-with-void-value, inconsistent-ifelse-braces, redundant-access-specifiers, static-definition-in-anonymous-namespace, and suspicious-call-argument. Slice's const and non-const conversions had the same body, so one const conversion replaces each pair. A dead branch in the Gist tree builder goes. The one suspicious-call-argument report is a symmetric call.
Remove the modernize exclusions that fit, with their fixes: loop-convert, use-using, type-traits, make-unique, make-shared, use-emplace, raw-string-literal, use-starts-ends-with, use-integer-sign-comparison, use-ranges, use-transparent-functors, min-max-use-initializer-list, and use-constraints. Also enable readability-redundant-typename and readability-non-const-parameter, which belong with these rewrites. The use-using fix-it drops const from aliases such as const_iterator, so each alias was compared with its typedef. The cpprofiler base name check compares against npos, which is what its cast to size_t meant. The cumulatives test sorts by position through a projection, since std::ranges::sort needs more than Event's operator<. The variable header generator skips identical modification event pairs and writes the clone list loop as a range-based loop. Special members that the earlier assignment and initializer fixes made trivial are now defaulted.
Enable modernize-concat-nested-namespaces, and generate the same form. Shallower indentation lets clang-format repack the tables in the MiniModel tests.
Enable the clang-analyzer cplusplus, deadcode, nullability, optin, security, unix, and valist groups, except the checks that only produce false positives here, and remove the dead stores they find, including an unused search timer in Gist. Enable these checks from other groups, with their fixes: - hicpp-exception-baseclass: FlatZinc::Error, AST::TypeError, and ShapeError derive from std::exception and provide what(); tests that unwound with a thrown int use std::logic_error. - google-default-arguments: a virtual function loses its default argument. - cppcoreguidelines-rvalue-reference-param-not-moved: only the empty branch filter and print function take an rvalue without moving it. - cppcoreguidelines-no-malloc: malloc stays inside the heap allocator. - cert-err33-c with casts to void allowed: unused C library results are discarded explicitly. - misc-use-internal-linkage for functions: file-local functions get internal linkage. - modernize-avoid-c-style-cast and modernize-avoid-variadic-functions, which make the LDSB test helper a variadic template. - cppcoreguidelines-misleading-capture-default-by-value, cppcoreguidelines-missing-std-forward, google-build-explicit-make-pair, and google-global-names-in-headers, which already pass. BranchPlugin gets a virtual destructor. A full lint finds what the per-check passes missed: declaration and definition names now agree, Cutoff::geometric no longer calls its scale base in the definition (it passed them in the right order all along), and the cumulative tests hold their usage table in a vector, which removes the analyzer's report on an empty allocation.
Lint stops at the first failing stage, so the grammar actions and parser.hh were reached only once everything else passed. yyerror keeps external linkage, because the lexer calls it, and is now declared once in parser.hh; the other parser functions become static. Token strings come from strdup, so one helper holds the free the check has to allow. The windows and none blackbox sources and the headers no linted source includes get the same namespace form, which a lint here cannot reach.
Record why each excluded check does not fit, so that a later review starts from the reasons, and which fix-its need care. Also restore bugprone-unused-return-value, which the switch to whole groups excluded by mistake, and note that MSVC rejects the unqualified ArgsType in the matrix slice conversion.
zayenz
force-pushed
the
feature/breaking-7
branch
from
December 1, 2026 16:46
fe46b74 to
8ea9ee1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the final PR of the eleven-PR Gecode 7 series: the clang-tidy sweep. It enables whole check groups in
.clang-tidy, excludes the checks that do not fit, and fixes what the enabled checks report. It is eight commits, each enabling its checks together with their fixes:(void)parameter lists (672 files, mechanical; the message holds the script that reproduces it).Commits 1 and 5 touch most files without changing behaviour, so they are kept apart and can go in
.git-blame-ignore-revs. Commits 3 and 4 are mostly fix-it rewrites:contains(),empty(),starts_with(), range-based loops,usingfortypedef,make_unique, else after return, matching parameter names, and the like.Changes that affect behaviour or the API, and deserve a closer look, are in commits 2 and 6:
NaryInterandNaryUniondropped their free list when assigned to themselves. Assignment operators now returnT&to*this.FlatZinc::Error,AST::TypeError, andShapeErrorderive fromstd::exceptionand providewhat(), and tests that threw a rawintusestd::logic_error._GNU_SOURCEinblackbox-backend.cpp), rvalue reference parameters must be moved,BranchPlugingets a virtual destructor, a virtual function loses its default argument, file-local functions get internal linkage, and the CRTP basesSparseTupleStateandBlockClientget private constructors.cplusplus,deadcode,nullability,optin,security,unix, andvalistgroups are enabled. The dead stores they find go, including an unused search timer in Gist, and every remaining suppression is documented in place.Commit 7 extends linting into the Bison grammar actions, the Flex lexer, and
parser.hh, making internal parser helpersstaticand isolating thefree()ofstrduptoken strings in one helper. Commit 8 records indocs/code-style.mdwhy each excluded check was left off, so later reviews start from the reasons.Tested at the tip on macOS: the build has no warnings, formatting and
misc/check.py lintpass, andcheckpasses 570 of 570. Every commit builds without warnings. Lint is clean only at the tip, as it was in the per-check series this replaces: a few= defaultand generated-table fixes land in commit 4, and the parser-action fixes in commit 7. Commit 3 is the one new intermediate state (its readability fixes used to come after the modernize ones), and it also passescheck.Stack
#242, #282, #283, #241, and #284 through #293 are merged. This PR targets
main, and #294 builds on it.