Skip to content

Gecode 7: clang-tidy sweep - #274

Draft
zayenz wants to merge 80 commits into
feature/breaking-7-10-scoped-enumsfrom
feature/breaking-7
Draft

zayenz wants to merge 80 commits into
feature/breaking-7-10-scoped-enumsfrom
feature/breaking-7

Conversation

@zayenz

@zayenz zayenz commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

This is the final PR of the eleven-PR Gecode 7 series, and the branch that originally held all of them. What remains here is the clang-tidy sweep: 80 commits, each enabling a single check or small group of checks and fixing what it reports, so every commit passes misc/check.py lint.

Most of the commits are small and mechanical: removing (void) parameter lists, switching to nested namespaces, replacing typedef with using, adopting range-based loops, contains(), empty(), starts_with(), make_unique, and make_shared, dropping redundant casts and else after return, and matching parameter names between declarations and definitions.

A smaller set of commits makes behavioral or API-visible changes and is worth a closer look:

  • Self-assignment handling: NaryInter and NaryUnion previously dropped their free list when assigned to themselves.
  • Exceptions and destructors: enables destructor exception-escape checks (marking three false positives), derives FlatZinc::Error, AST::TypeError, and ShapeError from std::exception with what(), and updates tests that threw raw int to use std::logic_error.
  • API and safety checks: rejects reserved identifiers (allowing _GNU_SOURCE in blackbox-backend.cpp), checks for likely swapped call arguments, checks that rvalue reference parameters are moved, gives BranchPlugin a virtual destructor, and drops a default argument from a virtual function.
  • Clang static analyzer groups: enables the analyzer groups that fit Gecode (cplusplus, deadcode, nullability, optin, security, unix, valist), removes dead stores (including an unused search timer in Gist), fixes a declaration/definition name mismatch in Cutoff::geometric, and documents every remaining suppression in place.
  • FlatZinc parser and lexer: extends linting into the Bison grammar actions, Flex lexer, and parser.hh, making internal parser helpers static and isolating the free() of strdup token strings in one helper.
  • Style and check documentation: docs/code-style.md records why each excluded clang-tidy check was left off so future reviews do not have to re-investigate them, and notes that new scoped enums may use PascalCase enumerators (as in EndReason::Limit).

Three late commits fix issues that CI caught on the earlier combined branch: a stray blank line in the unary test, two MSVC build failures (renaming Pack::calc_dff_lower_bound's template parameter l so MSVC does not resolve it to the data member l, and defining NOMINMAX in blackbox-exec.cpp after dropping parentheses around numeric_limits), and re-qualifying a matrix slice conversion for MSVC. I left them as separate commits rather than folding them back into the sweep commits they fix.

The final two commits record the .zdev development notes for the Gecode 7 work and then remove them so they are not merged into main.

Tested at the tip on macOS: the build produces no warnings; formatting, generated-source freshness, and misc/check.py lint all pass; and check passes 569 of 569.

Stack

Merge in this order. #242 targets main, and each later PR builds on the one before it so its diff shows only its own commits. The first four PRs are standalone search and random-number changes; #284 through #274 are the Gecode 7 changes split out of what used to be a single branch.

  1. Rank solutions with Space::compare in best-solution search #242 Rank solutions with Space::compare
  2. Rename the meta-search hooks to hub and spoke #282 Rename the meta-search hooks to hub and spoke
  3. Give meta search hub and spoke contexts and report why search ended #283 Hub and spoke contexts and end reasons
  4. Add extensible random generators with reproducible stream splitting #241 Splittable random generators
  5. Gecode 7: CMake-only C++23 build baseline #284 Gecode 7: build baseline
  6. Gecode 7: format the sources with LLVM 22 #285 Gecode 7: reformat
  7. Gecode 7: normalized API names, LT constants and Clang checks #286 Gecode 7: API names, LT constants, checks
  8. Gecode 7: post nothing for empty arrays #287 Gecode 7: empty arrays
  9. Gecode 7: pass large parameters by const reference #288 Gecode 7: const& parameters
  10. Gecode 7: state and assert the heap size contract #289 Gecode 7: heap contract
  11. Gecode 7: trivially copyable handles and defaulted special members #290 Gecode 7: modern classes
  12. Gecode 7: native float interval instead of Boost #291 Gecode 7: native float interval
  13. Gecode 7: bug fixes and Doxygen warnings #292 Gecode 7: bug fixes and Doxygen
  14. Gecode 7: scoped enums and descriptive constant names #293 Gecode 7: scoped enums
  15. Gecode 7: clang-tidy sweep #274 Gecode 7: clang-tidy sweep ← this PR

@zayenz
zayenz force-pushed the feature/breaking-7 branch 4 times, most recently from 08405b4 to bb0af29 Compare November 7, 2026 08:04
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
Enable the bugprone, concurrency, misc, modernize, performance,
portability, and readability groups as a whole. Each check that reports
something is excluded until it has been reviewed, so a later change either
removes an exclusion together with its fixes, or keeps it as a decision.

The three integer literal actions in lexer.lxx began on the line of the
rule, which readability-misleading-indentation reports in the generated
lexer.
Enable bugprone-incorrect-roundings. Adding 0.5 before truncating gives the
wrong result for values just below a half.
Enable bugprone-reserved-identifier. The one report is _GNU_SOURCE, which
gecode/flatzinc/blackbox-backend.cpp must define for glibc, so the check
allows it.
Enable bugprone-nondeterministic-pointer-iteration-order. The one report sorts
constraint pointers by argument count, which does not depend on addresses.
Enable bugprone-bitwise-pointer-cast. The memcpy copied an array of pointers
but read like a cast between pointer types.
Enable bugprone-suspicious-string-compare.
Enable bugprone-parent-virtual-call. LDSBSetBrancher calls ViewValBrancher
directly because the LDSB steps of its parent need its own symmetry update
first, or add prunings of their own.
Enable bugprone-crtp-constructor-accessibility. SparseTupleState and BlockClient
can now only be constructed by the class they were written for.
Enable bugprone-assignment-in-if-condition.
Enable misc-unconventional-assign-operator. Assignment operators that
returned a const reference now return T&, and those that returned the
converted result of a base assignment now call it and return *this.
Enable bugprone-unhandled-self-assignment. NaryInter and NaryUnion dropped their
free list when assigned to themselves. The copy members of TaskArray only
copied their fields, so they are now defaulted.
Enable misc-misplaced-const. const Tuple made the pointer const, not the tuple
it points at.
Enable misc-definitions-in-headers.
Enable 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 of them.
Enable misc-override-with-different-visibility. SteelMillBranch inherited from
Brancher privately by accident.
Enable misc-redundant-expression. The variable header generator wrote x ^ x into
the modification event tables, and now writes 0 instead.
Enable bugprone-empty-catch. A block may stay empty when a comment says the
exception is expected or ignored, which is what the tests and the blackbox
library cleanup do.
Enable bugprone-exception-escape, without main and the move members. Its only
reports there were main functions, which report nothing better by catching, and
the implicit members of value types and lambdas. The three remaining reports are
marked as false positives.
Enable readability-static-definition-in-anonymous-namespace.
Enable readability-container-size-empty.
Enable readability-container-contains. C++23 gives std::string the same member.
Enable readability-redundant-casting.
Enable readability-use-concise-preprocessor-directives.
Enable readability-static-accessed-through-instance.
Enable readability-redundant-member-init.
Enable cppcoreguidelines-rvalue-reference-param-not-moved. Only the empty branch filter and print function take an rvalue without moving it.
Enable hicpp-exception-baseclass. FlatZinc::Error, AST::TypeError, and ShapeError now provide what(), and the tests that unwind with a thrown int use std::logic_error.
Enable misc-use-internal-linkage for functions.
Enable clang-analyzer cplusplus, deadcode, nullability, optin, security, unix, and valist, except the checks that only produce false positives here. Remove the dead stores this finds, including the unused search timer in Gist.
The per-check sweeps missed these. The names in declarations and
definitions now agree, and Cutoff::geometric no longer calls its scale
base in the definition; it passed them in the right order all along.
The cumulative tests hold their usage table in a vector, which also
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.
Pack has a data member l, and MSVC resolves l in the out-of-line
definition of calc_dff_lower_bound to that member instead of to the
template parameter of the same name. Rename the parameter. This, rather
than the function-typed parameter that 50707a2 changed, is what
MSVC rejected.

Removing the redundant parentheses around numeric_limits members in
blackbox-exec.cpp exposed them to the min and max macros of windows.h,
so define NOMINMAX as blackbox-backend.cpp does.
d86ed2f fixed this, and a44934b dropped the qualification when it
removed the const conversions. Note why it is there.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant