From 0574030c01615d4ce26de0d9b0d64292ab3eac9b Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Mon, 30 Mar 2020 13:13:07 +0200 Subject: [PATCH] [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. --- clang/lib/Format/TokenAnnotator.cpp | 2 +- clang/unittests/Format/FormatTestCSharp.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 8a1e247..8f40fc7 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1047,7 +1047,7 @@ private: 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 17b8e07..f5e0bab 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -709,6 +709,14 @@ class ItemFactory IAnotherInterface, IAnotherInterfaceStill {})", 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 -- 2.7.4