Author: Marek Kurdej Date: 2022-03-08T13:35:26+01:00 New Revision: f537a409160dc1e506445724c5256bb116c0d71a
URL: https://github.com/llvm/llvm-project/commit/f537a409160dc1e506445724c5256bb116c0d71a DIFF: https://github.com/llvm/llvm-project/commit/f537a409160dc1e506445724c5256bb116c0d71a.diff LOG: [clang-format] Correctly detect `!` as TT_NonNullAssertion after `default`. Fixes https://github.com/llvm/llvm-project/issues/53153. Depends on D121132. Reviewed By: HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D121136 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 236e9a73b33a8..8f5f4e0f43362 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1650,9 +1650,9 @@ class AnnotatingParser { : Current.Previous->is(tok::identifier); if (IsIdentifier || Current.Previous->isOneOf( - tok::kw_namespace, tok::r_paren, tok::r_square, tok::r_brace, - tok::kw_false, tok::kw_true, Keywords.kw_type, Keywords.kw_get, - Keywords.kw_init, Keywords.kw_set) || + tok::kw_default, tok::kw_namespace, tok::r_paren, tok::r_square, + tok::r_brace, tok::kw_false, tok::kw_true, Keywords.kw_type, + Keywords.kw_get, Keywords.kw_init, Keywords.kw_set) || Current.Previous->Tok.isLiteral()) { Current.setType(TT_NonNullAssertion); return; diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp index 2a7642012a5f9..aa0304f73fed4 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -1078,6 +1078,26 @@ public class SaleItem MicrosoftStyle); } +TEST_F(FormatTestCSharp, DefaultLiteral) { + FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp); + + verifyFormat( + "T[] InitializeArray<T>(int length, T initialValue = default) {}", Style); + verifyFormat("System.Numerics.Complex fillValue = default;", Style); + verifyFormat("int Value { get } = default;", Style); + verifyFormat("int Value { get } = default!;", Style); + verifyFormat(R"(// +public record Person { + public string GetInit { get; init; } = default!; +};)", + Style); + verifyFormat(R"(// +public record Person { + public string GetSet { get; set; } = default!; +};)", + Style); +} + TEST_F(FormatTestCSharp, CSharpSpaces) { FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp); Style.SpaceBeforeSquareBrackets = false; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits