Skip to content

fix(braces): exempt C++20 templated lambdas from trailing-semicolon check - #458

Open
breidenbach0 wants to merge 2 commits into
cpplint:developfrom
breidenbach0:fix-385-templated-lambda-semicolon
Open

fix(braces): exempt C++20 templated lambdas from trailing-semicolon check#458
breidenbach0 wants to merge 2 commits into
cpplint:developfrom
breidenbach0:fix-385-templated-lambda-semicolon

Conversation

@breidenbach0

@breidenbach0 breidenbach0 commented Jul 31, 2026

Copy link
Copy Markdown

Fixes #385.

Problem: a C++20 templated lambda like []<typename T>(T&& t) { ... }; was falsely flagged readability/braces"You don't need a ; after a }."

Cause: CheckTrailingSemicolon exempts lambdas by checking that the text before ( ends in ] (the capture). A templated lambda puts <T> between ] and (, so the prefix ends in > and the exemption missed it.

Fix: also recognise the ]<...> lambda introducer.

Testing:

  • templated lambdas ([]<T>, [&]<T>, multi-param, multi-line, []<auto>) → no longer flagged
  • non-templated lambda → still exempted (unchanged)
  • real redundant ; (function / for / while / if, including a templated function) → still flagged
  • pytest cpplint_unittest.py → 206 passed; the new regression tests fail without the fix.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed false redundant trailing semicolon warnings for C++20 templated lambdas.
    • Preserved warnings for ordinary templated functions with redundant trailing semicolons.
  • Tests

    • Added coverage for single-line and multi-line C++20 templated lambda expressions.
  • Documentation

    • Updated the changelog with details of the warning fix.

breidenbach0 and others added 2 commits July 29, 2026 14:48
…heck

A C++20 templated lambda like []<typename T>(T&& t) { ... }; was falsely
flagged with readability/braces 'You don't need a ; after a }'. The lambda
exemption relied on the text before '(' ending in ']' (the capture), but a
template parameter list sits between ']' and '(' so the prefix ends in '>'
and the exemption missed it. Also recognize the ]<...> introducer.

Fixes cpplint#385
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2959966e-c9b3-4000-a24b-a3c63ccc50d6

📥 Commits

Reviewing files that changed from the base of the PR and between bb2f8a6 and c6a64d4.

📒 Files selected for processing (3)
  • CHANGELOG.rst
  • cpplint.py
  • cpplint_unittest.py

📝 Walkthrough

Walkthrough

The trailing-semicolon check now suppresses false warnings for C++20 templated lambdas. Regression tests cover single-line and multi-line lambdas and retain warnings for ordinary templated functions. The changelog documents the fix.

Changes

Templated Lambda Semicolon Handling

Layer / File(s) Summary
Trailing-semicolon detection and regression coverage
cpplint.py, cpplint_unittest.py, CHANGELOG.rst
The checker excludes lambda/template-call expressions from redundant trailing-semicolon warnings. Tests cover valid C++20 templated lambdas and preserve warnings for redundant semicolons after templated functions. The changelog records the fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • cpplint/cpplint#454: Both changes modify CheckTrailingSemicolon and related templated-lambda tests.

Suggested reviewers: aaronliu0130, janmarsino98

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the fix for C++20 templated lambdas and the trailing-semicolon check.
Linked Issues check ✅ Passed The change fixes issue #385 by exempting C++20 templated lambdas while retaining warnings for redundant semicolons elsewhere.
Out of Scope Changes check ✅ Passed The changelog, implementation, and regression tests directly support the linked issue and PR objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@androvonx95 androvonx95 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.

Reviewed at c6a64d4 against current develop.

The same-line / simple multi-line-body cases are fixed, including the exact #385 example, and a templated function still warns. Full suite: 206 passed.

The \\s*<.*>\\s*$ check only looks at the text before ( on that line, so these valid forms still emit readability/braces here (clean on #454):

auto identity = []<
    typename T
>(T&& t) { return t; };

auto identity = []
<typename T>
(T&& t) { return t; };

auto identity = []<typename T>
(T&& t) { return t; };

auto identity = []<typename T>
    requires std::integral<T>
(T&& t) { return t; };

Each compiles under g++ -std=c++20 -pedantic-errors -fsyntax-only. Given the overlap/conflict with #454, I’d lean toward closing this in favor of that PR unless you extend coverage to the multiline/requires cases.

@yangfan-yf-yf yangfan-yf-yf 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.

I independently rechecked c6a64d4 and confirmed that the multiline template and requires-clause cases already reported in the existing review still emit readability/braces on this head, while #454 handles the same inputs and preserves diagnostics for multiline operator[] declarations and constrained functions. Since the two PRs overlap and conflict, I don't think this narrower implementation should merge as-is. Unless this branch is broadened beyond #454, I recommend closing it in favor of #454.

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.

false positive: semicolon after a templated lambda

3 participants