Skip to content

Commit 059f2df

Browse files
authored
[clang-format] Fix an assertion failure on comment-only config files (#163111)
1 parent f4e906a commit 059f2df

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/Format/Format.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2184,8 +2184,9 @@ std::error_code parseConfiguration(llvm::MemoryBufferRef Config,
21842184
Input >> Styles;
21852185
if (Input.error())
21862186
return Input.error();
2187+
if (Styles.empty())
2188+
return make_error_code(ParseError::Success);
21872189

2188-
assert(!Styles.empty());
21892190
const auto StyleCount = Styles.size();
21902191

21912192
// Start from the second style as (only) the first one may be the default.

clang/unittests/Format/ConfigParseTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,13 @@ TEST(ConfigParseTest, ParsesConfigurationWithLanguages) {
12641264
IndentWidth, 56u);
12651265
}
12661266

1267+
TEST(ConfigParseTest, AllowCommentOnlyConfigFile) {
1268+
FormatStyle Style = {};
1269+
Style.Language = FormatStyle::LK_Cpp;
1270+
EXPECT_EQ(parseConfiguration("#Language: C", &Style), ParseError::Success);
1271+
EXPECT_EQ(Style.Language, FormatStyle::LK_Cpp);
1272+
}
1273+
12671274
TEST(ConfigParseTest, AllowCppForC) {
12681275
FormatStyle Style = {};
12691276
Style.Language = FormatStyle::LK_C;

0 commit comments

Comments
 (0)