Skip to content

Enable readability-braces-around-statements in clang-tidy - #390

Merged
xlamorlette-datadog merged 2 commits into
mainfrom
automated/clang-tidy-missing-braces-2026-10-17
Oct 23, 2026
Merged

xlamorlette-datadog merged 2 commits into
mainfrom
automated/clang-tidy-missing-braces-2026-10-17

Conversation

@dd-apm-ecosystems

Copy link
Copy Markdown
Contributor

Overview

Enable readability-braces-around-statements in the shared clang-tidy baseline (.clang-tidy), wired into the existing clang-tidy CI step (bin/check-tidy, run from .github/workflows/dev.yml).

Motivation

Reviewers have repeatedly asked contributors to add braces around single-line if/return bodies in C++ changes. This is a recurring, mechanical review comment that a clang-tidy check can enforce automatically instead of a human re-raising it on every PR.

Additional Notes

This repo's src/ tree (the tree scanned by bin/check-tidy) already has no brace-less control statements, so enabling the check requires no source changes here — it is a config-only change. The companion check is also being proposed in httpd-datadog and nginx-datadog, which share this .clang-tidy baseline and do have a small number of existing brace-less statements to fix alongside enabling the check there.

References

Jira ticket:

Contributor Checklist

  • I am the author of this pull request and I own it.
  • I reviewed every line of this pull request.
  • This pull request follows the Contributing Guidelines.

Additional context (automated analysis)

This PR was opened by an automated clang-tidy-review workflow that scans PR activity across DataDog/dd-trace-cpp, DataDog/httpd-datadog, and DataDog/nginx-datadog for recurring, automatable C++ review themes.

Theme: Missing braces around single-line if/return control-flow bodies (readability-braces-around-statements).

Observed in: 4 occurrences across 2 repos / 4 distinct PRs (recurrence bar requires ≥2 distinct PRs):

Verification: src/ and include/ in this repo were checked (via GitHub content reads of span.cpp, trace_segment.cpp, tracer.cpp, trace_sampler.cpp, w3c_propagation.cpp, and targeted search_code queries for brace-less if (...) return ...; patterns) and found clean of this pattern already, so this change is config-only and should not fail the existing clang-tidy CI job.

Not actioned this run (reported for completeness):

  • readability-magic-numbers — recurring (dd-trace-cpp#286, dd-trace-cpp#330, nginx-datadog#304) but has a high false-positive rate against existing code (e.g. HTTP/protocol version constants, array sizes) and would need case-by-case suppression; skipped per the "require low false-positive rate" guardrail.
  • C-style/functional-style casts (cppcoreguidelines-pro-type-cstyle-cast) — recurring (dd-trace-cpp#286, nginx-datadog#304) but src/datadog/trace_sampler.cpp has several pre-existing functional-style casts (int(rule.mechanism), etc.) and clang-tidy here runs over the whole src/ tree (no per-diff scoping mechanism exists), so enabling it now would break CI on pre-existing code.
  • Manual new/delete instead of RAII — recurring (httpd-datadog#88, nginx-datadog#304) but the observed instances are deliberate C-API interop with pool-scoped lifetimes (APR/ngx pools), not accidental ownership bugs; bugprone-unused-raii (already enabled) covers the genuine bug case.

Recurring review theme: reviewers across dd-trace-cpp and httpd-datadog
have repeatedly asked for braces around single-line if/return bodies
(dd-trace-cpp#286, dd-trace-cpp#295, dd-trace-cpp#313, httpd-datadog#62).
This repo's src/ tree already has no brace-less control statements, so
enabling the check needs no source changes here.
@colin-higgins
colin-higgins marked this pull request as ready for review October 23, 2026 14:43
@colin-higgins
colin-higgins requested review from a team as code owners October 23, 2026 14:43
@colin-higgins
colin-higgins requested review from dubloom and removed request for a team October 23, 2026 14:43
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-23T14:43:29.612335Z f7ccec3 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: FAIL

Enabling the new brace-enforcement clang-tidy rule without first fixing existing violations in src/datadog/w3c_propagation.cpp (line 151) and src/datadog/platform_util_unix.cpp (lines 183–186) will break CI, because WarningsAsErrors: '*' turns these diagnostics into hard failures for bin/check-tidy.

Open Bits AI session

🤖 Bits Code Review · Commit f7ccec3

Comment thread .clang-tidy
@xlamorlette-datadog

Copy link
Copy Markdown
Collaborator

To allow one-line condition block, such as:

if (env_host && env_host->empty()) env_host = nullopt;

It seems we can try:

CheckOptions:
  - key: readability-braces-around-statements.ShortStatementLines
    value: 1

@pr-commenter

pr-commenter Bot commented Oct 23, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-10-23 15:24:40

Comparing candidate commit 6d6d377 in PR branch automated/clang-tidy-missing-braces-2026-10-17 with baseline commit 4c9520b in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 8 metrics, 0 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

@xlamorlette-datadog
xlamorlette-datadog removed the request for review from dubloom October 23, 2026 15:42
@xlamorlette-datadog
xlamorlette-datadog merged commit eea55d8 into main Oct 23, 2026
68 of 70 checks passed
@xlamorlette-datadog
xlamorlette-datadog deleted the automated/clang-tidy-missing-braces-2026-10-17 branch October 23, 2026 15:42
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