-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Codestyle] Set clang-format RemoveSemicolon
rule to true
#97934
base: master
Are you sure you want to change the base?
[Codestyle] Set clang-format RemoveSemicolon
rule to true
#97934
Conversation
RemoveSemicolon
rule to true
RemoveSemicolon
rule to true
b637c9b
to
5eabacd
Compare
5eabacd
to
8e29735
Compare
120802c
to
f125b8e
Compare
- Set clang-format `Standard` rule to `c++20` - Add `FORCE_SEMICOLON` macro in core/typedefs.h
f125b8e
to
2a1de2a
Compare
See also: For a different approach (which doesn't apply to CI but allows us to fix this) |
SCOPE_EXIT { | ||
_recursion_flag_ = false; | ||
}; | ||
} | ||
FORCE_SEMICOLON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an example of the use of FORCE_SEMICOLON
. Only use when the formatter is stubborn removing a necessary semi-colon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively:
SCOPE_EXIT { // clang-format off
_recursion_flag_ = false;
}; // clang-format on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. Like, yeah it works, but what if a format error is introduced between them?
What I mean is that it's the only case in the whole codebase that it occurs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If format errors in between are the concern, just move the // clang-format off
down one line. Because the settings only apply to subsequent lines, this will turn clang-format off only for the line with the semicolon.
SCOPE_EXIT {
_recursion_flag_ = false; // clang-format off
}; // clang-format on
While that's the option I'd prefer most, here's two more alternatives: after looking at the SCOPE_EXIT
macro, it turns out this is the only place in the entire repo where it's used. I'd sooner say to either remove that macro entirely, or replace it with a version that wraps the content itself, both of which will fix clang-format removing the semicolon.
gdmono::ScopeExit GD_UNIQUE_NAME(gd_scope_exit) = gdmono::ScopeExitAux() + [=]() -> void {
_recursion_flag_ = false;
};
#define SCOPE_EXIT(m_content) \
auto GD_UNIQUE_NAME(gd_scope_exit) = gdmono::ScopeExitAux() + [=]() -> void { m_content };
//////////
SCOPE_EXIT(_recursion_flag_ = false;)
I prefer these workarounds because I see FORCE_SEMICOLON
better used for ensuring a trailing semicolon on macro. Here's an excerpt from one of my prospective PRs that wanted to tackle this on the clang-tidy scope:
// By appending to a macro, ensures that it'll require a trailing semicolon.
#ifndef FORCE_SEMICOLON
#define FORCE_SEMICOLON static_assert(true)
#endif
static_assert
produces zero build-time bloat, being a functionally "free" addition (especially in this always-true context). What it does provide is a way to require a trailing semicolon in virtually any context, as static_assert
requires a semicolon to follow its declaration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree with FORCE_SEMICOLON
being added in this context (see #97934 (comment)), but I'm otherwise onboard with this! I'd recommend a .git-blame-ignore-revs
commit as well, as there's no functional changes to speak of.
FORCE_SEMICOLON
macro to force a semi-colon to be inserted (and bypass clang-format).RemoveSemicolon
rule totrue
#97934 (review) for an example.Standard
rule toc++20
(as there's currently a c++20 feature in the codebase that messes up with semi-colons otherwise)This should fix the superfluous semi-colons issue that takes a lot of time for some reviewers to flag in PRs.