-
Notifications
You must be signed in to change notification settings - Fork 592
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
clang-format for C++ #1851
clang-format for C++ #1851
Conversation
Would be good to apply the format to see the actual changes. |
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 run clang-format -i and changes look overall fine, we should wait until there isn't any large outgoing PRs to format the code.
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.
Looks good!!!
I agree, would be nice to get this in soon though. |
I applied it to the C++ code so that you can see it on your favorite code. I am not proposing to merge this PR as-is - we need to coordinate to avoid big merge conflicts. I had to disable include sorting as it broke the build. We also need to write a separate clang format for the Objective-C/C++ code, including the header files. |
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 think it's an improvement in general.
But there were a few things that looked weird in the 20 or so files I skimmed.
|
||
virtual void shutdown(const Ice::Current& current) | ||
{ | ||
current.adapter->getCommunicator()->shutdown(); | ||
} | ||
virtual void shutdown(const Ice::Current& current) { current.adapter->getCommunicator()->shutdown(); } |
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.
Even though this does fit within a 120 column line,
I think it's more readable to keep all but the trivialist of functions on multiple lines.
If there's no way to tweak this, so be it.
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.
There's a configuration option for this:
https://clang.llvm.org/docs/ClangFormatStyleOptions.html#allowshortfunctionsonasingleline
But it doesn't let you change it's behavior based on the length of the function body...
There are some other options for it that I think are worth looking at.
Personally, I'd prefer Empty
or Inline
... it's hard to tell what the values are by default.
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 prefer this kind of code on one line.
cpp/src/Slice/Grammar.h
Outdated
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.
Should we add an exception for all the Bison generated files (so the formatter ignores them)?
A) No sane person will ever read this code
B) Regenerating the parsers will be slightly more painful if we need to fix the formatting of them
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.
This would be desirable. I didn't research how to do it.
# define GLACIER2_API ICE_DECLSPEC_EXPORT | ||
# else | ||
# define GLACIER2_API ICE_DECLSPEC_IMPORT | ||
# endif | ||
#endif | ||
|
||
namespace Glacier2Internal | ||
{ | ||
|
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.
What's everyone's thoughts on this trailing/leading whitespace around namespaces?
I've mostly only seen:
namespace Foo
{
stuff
}
and
namespace Foo
{
stuff
}
So, what we're doing now feels kind of weird:
namespace Foo
{
stuff
}
I personally think the 2nd option looks the best, and it's also what cppreference uses:
https://en.cppreference.com/w/cpp/language/namespace
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.
Doesn't look there's a way to enforce this with the formatter... sad.
Could probably still be fixed with a regex if everyone else agrees it looks weird.
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 prefer 2nd option too
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.
Yes, we should remove these blank lines. They were not inserted by the formatter, it's just a consequence of our current zero-indent in namespace formatting.
What about adding:
I think it would be more consistent with our IceRCP C# style, for example:
|
Applied. |
Replaced by #1916. |
The goal is have C++ format that is close to:
And of course that looks nice.
Here is my initial attempt. Give it a try and improve it!