[clang] 0574030 - [clang-format] only parse C# generic type constraints in C#
Krasimir Georgiev via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 30 04:22:05 PDT 2020
Author: Krasimir Georgiev
Date: 2020-03-30T13:13:07+02:00
New Revision: 0574030c01615d4ce26de0d9b0d64292ab3eac9b
URL: https://github.com/llvm/llvm-project/commit/0574030c01615d4ce26de0d9b0d64292ab3eac9b
DIFF: https://github.com/llvm/llvm-project/commit/0574030c01615d4ce26de0d9b0d64292ab3eac9b.diff
LOG: [clang-format] only parse C# generic type constraints in C#
Commit "[clang-format] Handle C# generic type constraints",
https://github.com/llvm/llvm-project/commit/dcbcec4822f47ec5b638dd9c20dcebd464569dae
regressed the formatting of code containing `where` as an identifier in other
languages.
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestCSharp.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 8a1e247463d5..8f40fc7bdcb6 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1047,7 +1047,7 @@ class AnnotatingParser {
Keywords.kw___has_include_next)) {
parseHasInclude();
}
- if (Tok->is(Keywords.kw_where) && Tok->Next &&
+ if (Style.isCSharp() && Tok->is(Keywords.kw_where) && Tok->Next &&
Tok->Next->isNot(tok::l_paren)) {
Tok->Type = TT_CSharpGenericTypeConstraint;
parseCSharpGenericTypeConstraint();
diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp
index 17b8e070c36a..f5e0bab1cb31 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -709,6 +709,14 @@ class ItemFactory<T>
IAnotherInterface<T>,
IAnotherInterfaceStill<T> {})",
Style);
+
+ // In other languages `where` can be used as a normal identifier.
+ // This example is in C++!
+ verifyFormat(R"(//
+class A {
+ int f(int where) {}
+};)",
+ getGoogleStyle(FormatStyle::LK_Cpp));
}
} // namespace format
More information about the cfe-commits
mailing list