-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[Format] Configure ASSIGN_OR_RETURN macros for Google style #169037
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
base: main
Are you sure you want to change the base?
Conversation
Change is originally authored by Daniel Jasper, who asked me to send this PR upstream.
|
@llvm/pr-subscribers-clang-format Author: Ilya Biryukov (ilya-biryukov) ChangesChange is originally authored by Daniel Jasper, who asked me to send this PR upstream. Full diff: https://github.com/llvm/llvm-project/pull/169037.diff 3 Files Affected:
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 9bbb33cb14502..20ea81cf429cc 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1961,6 +1961,10 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
GoogleStyle.PenaltyBreakBeforeFirstCallParameter = 1;
GoogleStyle.PenaltyReturnTypeOnItsOwnLine = 200;
+ GoogleStyle.Macros.push_back("ASSIGN_OR_RETURN(a, b)=a = (b)");
+ GoogleStyle.Macros.push_back(
+ "ASSIGN_OR_RETURN(a, b, c)=a = (b); if (x) return c");
+
if (Language == FormatStyle::LK_Java) {
GoogleStyle.AlignAfterOpenBracket = false;
GoogleStyle.AlignOperands = FormatStyle::OAS_DontAlign;
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index d578fa7a1a1e8..1e1621d8422e9 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -967,6 +967,7 @@ TEST(ConfigParseTest, ParsesConfiguration) {
std::vector<std::string>({"QUNUSED", "QT_REQUIRE_VERSION"}));
CHECK_PARSE_LIST(JavaImportGroups);
+ Style.Macros.clear();
CHECK_PARSE_LIST(Macros);
CHECK_PARSE_LIST(MacrosSkippedByRemoveParentheses);
CHECK_PARSE_LIST(NamespaceMacros);
diff --git a/clang/unittests/Format/FormatTestMacroExpansion.cpp b/clang/unittests/Format/FormatTestMacroExpansion.cpp
index d391fe3d715c3..0b15f21be0ddf 100644
--- a/clang/unittests/Format/FormatTestMacroExpansion.cpp
+++ b/clang/unittests/Format/FormatTestMacroExpansion.cpp
@@ -63,6 +63,14 @@ TEST_F(FormatTestMacroExpansion, UnexpandConfiguredMacros) {
"ReturnMe());",
Style);
+ verifyFormat("void f() {\n"
+ " ASSIGN_OR_RETURN(MySomewhatLongType* variable,\n"
+ " MySomewhatLongFunction(SomethingElse()));\n"
+ " ASSIGN_OR_RETURN(MySomewhatLongType* variable,\n"
+ " MySomewhatLongFunction(SomethingElse()), "
+ "ReturnMe());",
+ getGoogleStyle());
+
verifyFormat(R"(
#define MACRO(a, b) ID(a + b)
)",
|
🐧 Linux x64 Test Results
|
|
Can you link to some documentation for these macros? And maybe adapt the commit message. If you want to attribute it to a different person, commit in their name. ( |
| GoogleStyle.Macros.push_back("ASSIGN_OR_RETURN(a, b)=a = (b)"); | ||
| GoogleStyle.Macros.push_back( | ||
| "ASSIGN_OR_RETURN(a, b, c)=a = (b); if (x) return c"); | ||
|
|
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.
shouldn't this just be GoogleStyle.Macros.push_back("ASSIGN_OR_RETURN")?
| std::vector<std::string>({"QUNUSED", "QT_REQUIRE_VERSION"})); | ||
|
|
||
| CHECK_PARSE_LIST(JavaImportGroups); | ||
| Style.Macros.clear(); |
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.
why would you need this?
Change is originally authored by Daniel Jasper, who asked me to send this PR upstream.