Skip to content

[None][doc] Update C++ coding guidelines.#12577

Merged
achartier merged 2 commits intoNVIDIA:mainfrom
hnover-nv:cpp-coding-guidelines
Apr 6, 2026
Merged

[None][doc] Update C++ coding guidelines.#12577
achartier merged 2 commits intoNVIDIA:mainfrom
hnover-nv:cpp-coding-guidelines

Conversation

@hnover-nv
Copy link
Copy Markdown
Collaborator

@hnover-nv hnover-nv commented Mar 29, 2026

Major changes:

  • Add struct vs class guidance based on invariants, with designated initializer and default member initializer recommendations
  • Add east-const rule (enforced by clang-format QualifierAlignment: Right)
  • Relax g/s prefix requirements for global and static variables from mandatory to encouraged; consolidate three rules into one with clear categories (true global, file-scope, function-local static)
  • Change constant naming convention from kUPPER_SNAKE_CASE to kCamelCase, matching the dominant codebase convention (~77 vs ~13 occurrences)
  • Add singleton accessor function-lcoal static pattern as preferred alternative to bare global/static variables. Required for non-POD constants
  • Add enum class guidance with naming conventions
  • Recommend #pragma once over traditional include guards
  • Allow return as switch case terminator
  • Add anonymous namespace, X-macro, bugprone-argument-comment examples
  • Note historical inconsistency; new code should follow guidelines

Test Coverage

None

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

Summary by CodeRabbit

  • Documentation
    • Updated C++ coding guidelines with clearer rules for constants, namespaces, casting, and switch statements.
    • Enhanced struct vs. class usage guidance with detailed examples and best practices.
    • Added preprocessor conventions including #pragma once support.
    • Improved pointer-to-const and const-pointer clarification.
    • Added guidance for range-based for loops and iterators.

Major changes:
- Add struct vs class guidance based on invariants, with designated
  initializer and default member initializer recommendations
- Add east-const rule (enforced by clang-format QualifierAlignment: Right)
- Relax g/s prefix requirements for global and static variables from
  mandatory to encouraged; consolidate three rules into one with clear
  categories (true global, file-scope, function-local static)
- Change constant naming convention from kUPPER_SNAKE_CASE to kCamelCase,
  matching the dominant codebase convention (~77 vs ~13 occurrences)
- Add singleton accessor function-lcoal static pattern as preferred
  alternative to bare global/static variables. Required for non-POD
  constants
- Add enum class guidance with naming conventions
- Recommend #pragma once over traditional include guards
- Allow return as switch case terminator
- Add anonymous namespace, X-macro, bugprone-argument-comment examples
- Note historical inconsistency; new code should follow guidelines

Signed-off-by: Harris Nover <249353502+hnover-nv@users.noreply.github.com>
@hnover-nv hnover-nv requested a review from a team as a code owner March 29, 2026 21:39
@hnover-nv hnover-nv requested review from QiJune and nv-guomingz March 29, 2026 21:39
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 29, 2026

📝 Walkthrough

Walkthrough

Updated C++ coding guidelines to enhance standards for namespaces, constants, formatting, casting, switch statements, struct/class usage, preprocessor directives, and pointer declarations. Changes include explicit tooling-alignment directives, expanded const requirements and naming conventions, an invariants-based framework for struct/class selection, and refined guidance on range-based loops and pointer qualifiers.

Changes

Cohort / File(s) Summary
Coding Guidelines
CODING_GUIDELINES.md
Comprehensive expansion of C++ standards covering: anonymous namespace closing-brace comments; const requirements for local/global variables (excluding parameters) in east-const form; prohibition of non-POD globals with function-local static accessor patterns; strengthened formatting/comment enforcement via auto-run/CI; casting rules with explicit guidance on static_cast, reinterpret_cast, and dynamic_cast avoidance; refined switch-statement termination rules allowing break, throw, or return; new invariants-based struct vs. class framework with examples and designated-initializer preferences; enhanced preprocessor guidance including #pragma once convention and X-macro localized define/undef; recommendation to prefer range-based for loops; and clarified pointer-to-const vs. const-pointer distinctions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: updating C++ coding guidelines. It follows the repository's required format with ticket reference [None] and type [doc].
Description check ✅ Passed The PR description includes all key required sections: a clear explanation of major changes, test coverage (noted as None), and a completed PR checklist. The description is comprehensive and specific about the guideline updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@CODING_GUIDELINES.md`:
- Around line 165-172: The docs claim clang-tidy's bugprone-argument-comment
enforces the /*paramName=*/ format but it isn't actually enforced: ensure the
.clang-tidy configuration enables StrictMode for that check (set
bugprone-argument-comment.StrictMode = true in CheckOptions) so comments without
the '=' are flagged, and optionally add clang-tidy to .pre-commit-config.yaml so
bugprone-argument-comment runs automatically on pre-commit; reference the
bugprone-argument-comment check name and the StrictMode option when making the
changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9b40d93c-f667-4ffd-99ff-9fba3afad9e1

📥 Commits

Reviewing files that changed from the base of the PR and between 8ce0518 and 5eae848.

📒 Files selected for processing (1)
  • CODING_GUIDELINES.md

@hnover-nv
Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #40670 [ run ] triggered by Bot. Commit: 5eae848 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #40670 [ run ] completed with state SUCCESS. Commit: 5eae848
/LLM/main/L0_MergeRequest_PR pipeline #31702 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@hnover-nv
Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #40811 [ run ] triggered by Bot. Commit: 5eae848 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #40811 [ run ] completed with state SUCCESS. Commit: 5eae848
/LLM/main/L0_MergeRequest_PR pipeline #31825 completed with status: 'SUCCESS'

CI Report

Link to invocation

Copy link
Copy Markdown
Member

@lowsfer lowsfer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Signed-off-by: Harris Nover <249353502+hnover-nv@users.noreply.github.com>
@hnover-nv hnover-nv force-pushed the cpp-coding-guidelines branch from 0f7080f to bf586a4 Compare April 6, 2026 03:53
@hnover-nv
Copy link
Copy Markdown
Collaborator Author

/bot skip --comment "It passed in comment #12577 (comment) and it's just documentation anyway, so skipping"

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #41901 Bot args parsing error: Failed to parse bot args

Link to invocation

Copy link
Copy Markdown
Collaborator

@nv-guomingz nv-guomingz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hnover-nv
Copy link
Copy Markdown
Collaborator Author

/bot help

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

Details

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental) --high-priority]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

--high-priority (OPTIONAL) : Run the pipeline with high priority. This option is restricted to authorized users only and will route the job to a high-priority queue.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

@hnover-nv
Copy link
Copy Markdown
Collaborator Author

/bot skip --comment "It passed before and has a clean merge, and is just documentation, so skipping. Not sure why Jenkins wants it again, too old?"

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #41944 [ skip ] triggered by Bot. Commit: bf586a4 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #41944 [ skip ] completed with state SUCCESS. Commit: bf586a4
Skipping testing for commit bf586a4

Link to invocation

@achartier achartier merged commit 662e45f into NVIDIA:main Apr 6, 2026
5 checks passed
@hnover-nv hnover-nv deleted the cpp-coding-guidelines branch April 6, 2026 16:25
xinhe-nv pushed a commit to xinhe-nv/TensorRT-LLM that referenced this pull request Apr 7, 2026
Signed-off-by: Harris Nover <249353502+hnover-nv@users.noreply.github.com>
yufeiwu-nv pushed a commit to yufeiwu-nv/TensorRT-LLM that referenced this pull request Apr 7, 2026
Signed-off-by: Harris Nover <249353502+hnover-nv@users.noreply.github.com>
karen-sy pushed a commit to karen-sy/TensorRT-LLM that referenced this pull request Apr 7, 2026
Signed-off-by: Harris Nover <249353502+hnover-nv@users.noreply.github.com>
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.

5 participants