Skip to content

Add CppCoreGuidelines setup#21

Merged
vladiant merged 19 commits into
mainfrom
cppcoreguidelines_setup
Apr 28, 2026
Merged

Add CppCoreGuidelines setup#21
vladiant merged 19 commits into
mainfrom
cppcoreguidelines_setup

Conversation

@vladiant
Copy link
Copy Markdown
Owner

@vladiant vladiant commented Apr 27, 2026

Summary

Hardens the warning configuration for the traincascade and test_traincascade targets by introducing a curated set of compiler diagnostics inspired by the C++ Core Guidelines and the cppbestpractices baseline. Flags are split per compiler (GNU, Clang, MSVC) so each toolchain enables the strictest set it actually supports.

Motivation

The previous configuration only enabled -Wall -Wextra -Wpedantic -Werror (or /W4 /WX). That misses a large class of bugs (shadowing, sign/integer conversions, switch coverage, format issues, uninitialized reads, aliasing violations, etc.) that the Core Guidelines explicitly call out. This PR raises the baseline without rewriting any production code.

Changes

  • CMakeLists.txt
    • traincascade target: enable an extended warning set across MSVC / GCC / Clang. A few warnings that currently fire in legacy code (-Wold-style-cast, -Wsign-conversion, -Wconversion, MSVC /w14365) are commented out with a # Fix in code note so they can be re-enabled incrementally.
    • test_traincascade target: enables the full set including the warnings above, since the test code is clean.
  • CMakeLists.txt: build fixes for vendored dependencies (zlib, macOS).
  • GitHub Actions (ubuntu.yml, macos.yml, windows.yml, static_check.yml, codeql-analysis.yml): action version bumps, clang-tidy setup fix, disabled Java build, OpenCV version bump.

Per-compiler flag coverage

Common (GCC + Clang): -Wcast-qual -Wshadow -Wnull-dereference -Wmisleading-indentation -Wimplicit-fallthrough -Wswitch-enum -Wshift-negative-value -Wformat=2 -Wformat-security -fstrict-aliasing -Wstack-protector -fstack-protector-strong -Wnon-virtual-dtor -Woverloaded-virtual -Wuninitialized -Walloca -Wvla

GCC-only: -Wcast-align=strict -Warith-conversion -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Wshift-overflow=2 -Wstrict-aliasing=3 -Wmaybe-uninitialized

Clang-only: -Wcast-align -Wlogical-op-parentheses -Wshift-overflow -Wconditional-uninitialized -Wsometimes-uninitialized

MSVC: /Zc:__cplusplus /Zc:preprocessor /Zc:inline plus the /w14xxx set covering shadowing, conversions, switch/enum, fallthrough, format, virtual/override hygiene, and uninitialized reads.

Validation

  • CI updated and green on Ubuntu, macOS and Windows runners.
  • clang-tidy job fixed and running in static_check.yml.

Follow-ups

Re-enable the warnings currently commented out as # Fix in code once the corresponding issues in traincascade are cleaned up:

  • -Wold-style-cast
  • -Wconversion / -Wsign-conversion (MSVC /w14365)

@vladiant vladiant merged commit 36581a6 into main Apr 28, 2026
7 checks passed
@vladiant vladiant deleted the cppcoreguidelines_setup branch April 28, 2026 17:54
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