diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 8a1e247463d507..8f40fc7bdcb613 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 17b8e070c36a54..f5e0bab1cb3113 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