Author: owenca Date: 2025-10-20T09:53:00Z New Revision: 7e153f5372edb8f53b8576932cf5969187bf0484
URL: https://github.com/llvm/llvm-project/commit/7e153f5372edb8f53b8576932cf5969187bf0484 DIFF: https://github.com/llvm/llvm-project/commit/7e153f5372edb8f53b8576932cf5969187bf0484.diff LOG: [clang-format] Fix an assertion failure on comment-only config files (#163111) (cherry picked from commit 059f2df74898ff7f394dc8e60f746323499ae32b) Added: Modified: clang/lib/Format/Format.cpp clang/unittests/Format/ConfigParseTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index d4e3a1989cd71..5bdb810a3925b 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -2132,8 +2132,9 @@ std::error_code parseConfiguration(llvm::MemoryBufferRef Config, Input >> Styles; if (Input.error()) return Input.error(); + if (Styles.empty()) + return make_error_code(ParseError::Success); - assert(!Styles.empty()); const auto StyleCount = Styles.size(); // Start from the second style as (only) the first one may be the default. diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp index bbe1923e19ee1..ff42f09b90cf3 100644 --- a/clang/unittests/Format/ConfigParseTest.cpp +++ b/clang/unittests/Format/ConfigParseTest.cpp @@ -1249,6 +1249,13 @@ TEST(ConfigParseTest, ParsesConfigurationWithLanguages) { IndentWidth, 56u); } +TEST(ConfigParseTest, AllowCommentOnlyConfigFile) { + FormatStyle Style = {}; + Style.Language = FormatStyle::LK_Cpp; + EXPECT_EQ(parseConfiguration("#Language: C", &Style), ParseError::Success); + EXPECT_EQ(Style.Language, FormatStyle::LK_Cpp); +} + TEST(ConfigParseTest, AllowCppForC) { FormatStyle Style = {}; Style.Language = FormatStyle::LK_C; _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
