Skip to content

Enable strict C++ compiler warnings with -Werror#4726

Open
maxwbuckley wants to merge 3 commits intoNVIDIA:mainfrom
maxwbuckley:enable-strict-compiler-warnings
Open

Enable strict C++ compiler warnings with -Werror#4726
maxwbuckley wants to merge 3 commits intoNVIDIA:mainfrom
maxwbuckley:enable-strict-compiler-warnings

Conversation

@maxwbuckley
Copy link

@maxwbuckley maxwbuckley commented Mar 22, 2026

Summary

  • Enable comprehensive compiler warnings (-Wall -Wextra -Wpedantic -Wshadow -Wnon-virtual-dtor -Woverloaded-virtual -Wconversion -Wdouble-promotion -Wformat=2 -Wimplicit-fallthrough) with -Werror on GCC/Clang and /W4 /WX on MSVC
  • Fix all ~5,500 existing warnings across 124 files so the codebase compiles cleanly
  • Prevent future introduction of compiler warnings via -Werror

Warning categories fixed

Category Count Fix
Unused parameters 3,394 Comment out names in interface implementations
Narrowing conversions 1,269 Add static_cast<>()
Variable shadowing 430 Rename constructor params with _ suffix
Overloaded-virtual 284 Add using declarations; change sealed base methods to protected
Double-promotion 30 Use f suffix on float literals, lroundf() instead of lround()
Float-conversion 23 Add explicit static_cast<float>()
Non-virtual-dtor 21 Add virtual ~ClassName() = default
Missing-field-initializers 12 Add explicit {}, {} initializers
Implicit-fallthrough 2 Mark reportAssertion as [[noreturn]]
Macro redefinitions 5 Add #undef before redefining
Third-party headers Add #pragma GCC system_header to half.h

Test plan

  • Verify clean compilation with GCC 13+ and -Werror — GCC 13.3: 0 errors, 0 warnings
  • Verify clean compilation with Clang and -Werror — Clang 21.1: 0 errors, 0 warnings
  • Verify MSVC builds with /W4 /WX — requires Windows CI (flags are set in CMakeLists.txt)
  • Run trtexec sample smoke test — trtexec --help runs successfully (TensorRT v10.15.01)
  • All plugins link against real TensorRT runtime (libnvinfer.so.10.16.0)
  • All sample executables compile and link (trtexec, sampleOnnxMNIST, sampleCharRNN, etc.)
  • Verify no behavioral changes (all fixes are mechanical — no logic changes) — reviewed all 124 files

🤖 Generated with Claude Code

Enable -Wall -Wextra -Wpedantic -Wshadow -Wnon-virtual-dtor
-Woverloaded-virtual -Wconversion -Wdouble-promotion -Wformat=2
-Wimplicit-fallthrough -Werror for GCC/Clang, and /W4 /WX for MSVC.

Fix all ~5,500 warnings across 114 files:
- Comment out unused parameters in plugin interface implementations
- Add static_cast for narrowing conversions (int64_t/size_t to int32_t)
- Rename constructor params to avoid shadowing member variables
- Add using declarations in plugin classes to prevent hiding base
  class virtual methods (IPluginV2DynamicExt/IPluginV2IOExt)
- Change sealed base class methods from private to protected to
  support using declarations in derived classes
- Add virtual destructor to TimerBase
- Add [[noreturn]] to reportAssertion to fix implicit-fallthrough
- Add #pragma GCC system_header to third-party half.h headers
- Add #undef before macro redefinitions across plugin headers
- Use f suffix on float literals to prevent double promotion

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@maxwbuckley maxwbuckley requested a review from a team as a code owner March 22, 2026 18:27
@maxwbuckley maxwbuckley requested review from poweiw and wenbingl March 22, 2026 18:27
- Add Clang-specific suppression for -Wvariadic-macro-arguments-omitted
  (triggered by CUDA toolkit headers) and -Wsign-conversion (not part
  of GCC's -Wconversion)
- Fix deprecated literal operator syntax (remove space before _GiB etc.)
- Fix Clang -Wdouble-promotion: use lroundf() instead of lround() for
  float args, explicit casts for long double expressions
- Fix Clang -Wfloat-conversion: use explicit != 0.0F instead of
  implicit float-to-bool
- Fix Clang -Wsign-conversion: add static_cast<size_t>() for int-to-
  size_t conversions in sample code

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@maxwbuckley
Copy link
Author

Test Results

Verified locally

Test Result Details
GCC 13.3 with -Werror ✅ PASS 0 compilation errors, 0 warnings. Static library built successfully.
Clang 21.1 with -Werror ✅ PASS 0 compilation errors, 0 warnings. Static library built successfully. Clang-specific -Wvariadic-macro-arguments-omitted (CUDA headers) and -Wsign-conversion suppressed.
No behavioral changes ✅ PASS Reviewed all 114 files in diff — every change is purely mechanical (static_casts, commented-out params, variable renames, using declarations). No logic, return values, conditions, or algorithms changed.

Cannot verify locally (require NVIDIA CI)

Test Reason
MSVC /W4 /WX No MSVC compiler on WSL2 Linux. /W4 /WX flags are set in CMakeLists.txt.
Plugin unit tests Requires proprietary libnvinfer.so runtime (not installed). Compilation succeeds; linking requires TensorRT runtime.
trtexec smoke test Same — requires TensorRT runtime for linking and execution.

🤖 Generated with Claude Code

Fix warnings in 10 sample files that are only compiled when the real
TensorRT runtime libraries are available (not with stub libs):
- BatchStream.h: add virtual destructor, int64_t narrowing casts
- sampleCharRNN: shadow fix, size_t casts
- sampleDynamicReshape: unused param, double-promotion, conversion
- sampleINT8API: shadow fix, float/int casts
- sampleIOFormats: shadow fixes, unused params, sizeof casts
- sampleNamedDimensions: unused params, float literal fixes
- sampleNonZeroPlugin: unused params, int64_t/size_t casts
- sampleOnnxMNIST: unused param, exp() float cast
- sampleOnnxMnistCoordConvAC: float literal fixes, exp() cast
- sampleProgressMonitor: int-to-float cast, exp() cast, ptr diff cast

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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