fix(runtime/explicit): skip deleted constructors - #450
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughDeleted single-argument constructors are detected across multiline declarations and excluded from the ChangesDeleted constructor warning handling
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cpplint.py`:
- Around line 3931-3940: Update the constructor detection and related state
handling around explicit_constructor_match to recognize suffixes such as
noexcept before = delete;, and preserve deletion state when the declaration
continues onto subsequent lines before the deleted marker. Ensure deleted
constructors do not emit runtime/explicit, and add regression coverage for
same-line suffixes and multiline declarations.
🪄 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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 83d1e3b8-daa3-47fd-8b0c-3ebc77e753e5
📒 Files selected for processing (3)
CHANGELOG.rstcpplint.pycpplint_unittest.py
|
Addressed in The constructor matcher now checks the declaration suffix after the closing Added regressions for both forms. Validation: |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cpplint.py`:
- Around line 3942-3952: Update the constructor suffix parsing around the
deleted-constructor detection to track balanced parentheses, braces, and other
delimiters so braces inside nested noexcept(...) expressions do not terminate
the suffix early. Only stop at declaration-level terminators, then ensure the
existing is_deleted regex recognizes valid nested noexcept forms and add a
regression case covering a deleted constructor such as Foo(int)
noexcept(noexcept(T{})) = delete;.
🪄 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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 0273c0de-36f6-4978-8122-c43d9c96a9ea
📒 Files selected for processing (2)
cpplint.pycpplint_unittest.py
🚧 Files skipped from review as they are similar to previous changes (1)
- cpplint_unittest.py
|
Addressed the nested-expression case in The suffix reader now tracks parentheses, brackets, and braces, and only treats Added that regression alongside the existing one-line and multiline cases. Validation: |
|
One gap: the template <class T>
Foo(T v) requires Integral<T> = delete; // C++20, trailing requires-clause
Foo(int f) throw() = delete; // valid through C++17
Foo(int f) = delete("use Bar instead"); // C++26, P2573Each compiles under Since is_deleted = bool(
re.search(r"=\s*delete\s*(?:\(.*\))?\s*;\s*$", constructor_suffix, re.DOTALL)
)Tested locally on your branch: 206 tests pass, and no over-suppression — inline body, member-init body, declaration followed by a deleted overload, two constructors on one line, macro suffix, and a trailing |
There was a problem hiding this comment.
Reviewed at 962e80f. The _GetConstructorSuffix() approach is sound and the #386 case, the noexcept forms, and the split-line form are all clean.
Not approving yet: as noted in my comment above, the is_deleted regex enumerates allowed suffixes, so a trailing requires-clause, throw(), and C++26 = delete("reason") still emit runtime/explicit. Anchoring the match to the end of the extracted suffix fixes all three, passes the full suite, and doesn't over-suppress.
|
Addressed in
Added regressions for all three forms. Validation: |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cpplint_unittest.py (1)
1668-1689: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd positive controls for non-deleted suffixes.
These cases only verify suppression. Add corresponding non-deleted declarations such as
Foo(int f) requires Integral<int>;,Foo(int f) throw();, andFoo(int f) noexcept;expectingruntime/explicit; otherwise a suffix-parsing regression that skips these declarations could pass the tests.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cpplint_unittest.py` around lines 1668 - 1689, Add positive-control cases to the TestMultiLineLint coverage for non-deleted declarations: require `runtime/explicit` for declarations using `requires Integral<int>`, `throw()`, and `noexcept` suffixes. Keep the existing deleted-declaration suppression cases unchanged and place the new assertions alongside them.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@cpplint_unittest.py`:
- Around line 1668-1689: Add positive-control cases to the TestMultiLineLint
coverage for non-deleted declarations: require `runtime/explicit` for
declarations using `requires Integral<int>`, `throw()`, and `noexcept` suffixes.
Keep the existing deleted-declaration suppression cases unchanged and place the
new assertions alongside them.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: fb5fe3b1-688f-4ab5-ab05-e32c4a89529a
📒 Files selected for processing (2)
cpplint.pycpplint_unittest.py
🚧 Files skipped from review as they are similar to previous changes (1)
- cpplint.py
androvonx95
left a comment
There was a problem hiding this comment.
Rechecked at bea44fe. The three previously reported forms are now handled correctly, while equivalent non-deleted constructors still emit runtime/explicit. The full unit suite passes (206 tests). My concern is resolved — LGTM.
bea44fe to
453f31e
Compare
|
Rebased onto the current Validation after the rebase: |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cpplint_unittest.py (1)
1666-1673: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick winAdd a negative counterpart for the
requiresclause case.This test confirms that a templated single-parameter constructor with a trailing
requiresclause and= deleteproduces no warning. Add a companion test for the same declaration without= delete, to confirmruntime/explicitstill fires when the constructor is not deleted. This guards against a suffix scan that is too permissive and silently swallows therequiresclause together with legitimate declarations that should still warn.Suggested additional test
self.TestMultiLineLint( """ class Foo { template <class T> Foo(T value) requires Integral<T>; };""", "Single-parameter constructors should be marked explicit. [runtime/explicit] [4]", )🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cpplint_unittest.py` around lines 1666 - 1673, Add a companion TestMultiLineLint case beside the existing deleted-constructor test, using the same templated constructor with its trailing requires clause but omitting = delete; assert the expected runtime/explicit warning so suffix handling does not suppress valid diagnostics.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@cpplint_unittest.py`:
- Around line 1666-1673: Add a companion TestMultiLineLint case beside the
existing deleted-constructor test, using the same templated constructor with its
trailing requires clause but omitting = delete; assert the expected
runtime/explicit warning so suffix handling does not suppress valid diagnostics.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4a19f7e1-6374-42e4-ac4b-899803ed2435
📒 Files selected for processing (3)
CHANGELOG.rstcpplint.pycpplint_unittest.py
🚧 Files skipped from review as they are similar to previous changes (2)
- CHANGELOG.rst
- cpplint.py
Purpose
Fixes #386. Deleted single-argument constructors currently trigger
runtime/expliciteven though they cannot be called implicitly.Rationale
The explicit-constructor check classifies the parameter list but does not inspect the declaration suffix. It now recognizes a trailing
= delete;and skips the warning only for that declaration form. Non-deleted single-argument constructors retain the existing check.How did you test?
Foo(int f) = delete;alongside the existing missing-explicitcases.python -m pytest --no-cov cpplint_unittest.py -k testExplicitSingleArgumentConstructors -vv: 1 passed.python -m pytest --no-cov -q: 231 passed.python -m pylint cpplint.py.python -m pre_commit run --files CHANGELOG.rst cpplint.py cpplint_unittest.py.git diff --check.How to Verify
python -m pytest --no-cov cpplint_unittest.py -k testExplicitSingleArgumentConstructors -vv.runtime/explicitmessage while the existing ordinary constructor case still does.