Skip to content

Enable strict C++ compiler warnings and -Werror by default#2061

Open
maxwbuckley wants to merge 1 commit intoNVIDIA:masterfrom
maxwbuckley:enable-strict-compiler-warnings
Open

Enable strict C++ compiler warnings and -Werror by default#2061
maxwbuckley wants to merge 1 commit intoNVIDIA:masterfrom
maxwbuckley:enable-strict-compiler-warnings

Conversation

@maxwbuckley
Copy link
Copy Markdown

Summary

  • Enable -Wextra, -Wshadow=local, -Wnon-virtual-dtor, -Woverloaded-virtual, -Wimplicit-fallthrough in the base CXXFLAGS for both Makefile and CMake build systems
  • Enable -Werror by default (WERROR=1) so no new warnings can be introduced going forward
  • Fix all existing warnings across 79 source files to achieve a zero-warning build

Warning categories fixed

Warning Count Fix
-Wmissing-field-initializers ~343 = {0}= {}; complete partial aggregate inits
-Wunused-parameter ~180 Comment out names (type /*name*/); (void)param for conditionally-used params
-Wshadow=local ~34 Rename inner variables; prefix macro-internal vars with _
-Wunused-function ~10 Add inline to static header functions
-Wtype-limits 5 Remove always-false unsigned < 0 comparisons
-Wempty-body 4 Add braces around conditionally-empty TRACE() macro bodies
-Wimplicit-fallthrough 2 Add __attribute__((fallthrough))
Third-party NVTX ~192 #pragma GCC system_header on vendored header

Design decisions

  • -Wshadow=local instead of full -Wshadow**: Full -Wshadow produces ~1700 warnings from constructor parameters shadowing members (idiomatic C++). -Wshadow=local catches the genuinely dangerous local-shadows-local cases only.
  • WERROR=0 escape hatch: Developers can still build with make WERROR=0 during prototyping if needed.
  • Vendored NVTX headers: Suppressed via #pragma GCC system_header since modifying third-party code is impractical.

Test plan

  • Full clean build with CUDA 12.9 on RTX 5090 — zero C++ warnings, library links successfully
  • astyle formatter run on all modified files
  • Tuner plugin unit tests: 15/15 passed
  • All 10 example programs in docs/examples/ build cleanly under strict flags

🤖 Generated with Claude Code

Add -Wextra, -Wshadow=local, -Wnon-virtual-dtor, -Woverloaded-virtual,
and -Wimplicit-fallthrough to the base CXXFLAGS in both the Makefile and
CMake build systems. Enable -Werror by default (WERROR=1) so that no new
warnings can be introduced going forward.

Fix all existing warnings across the codebase (79 files):
- Replace {0} struct initializers with {} (value-initialization)
- Complete partial aggregate initializations with missing trailing fields
- Comment out unused parameter names in callback/interface functions
- Add __attribute__((fallthrough)) for intentional switch fallthroughs
- Remove always-false unsigned comparisons (unsigned < 0)
- Add braces around empty TRACE() macro bodies
- Rename shadowing local variables in macros and nested scopes
- Mark unused static header functions as inline
- Suppress warnings from vendored NVTX3 headers via #pragma GCC system_header

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@maxwbuckley maxwbuckley force-pushed the enable-strict-compiler-warnings branch from a81377d to ad0eac4 Compare March 22, 2026 16:55
@xiaofanl-nvidia
Copy link
Copy Markdown
Collaborator

Hi @maxwbuckley thank you for your contribution. However, this is a sweeping change on a fast moving code base so we will need to do this in a phase manner and interleave with other feature development efforts.

I'm opening up an internal RFE to track the general suggestion to fix all compile time warnings and adding it to our roadmap.

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.

2 participants