Skip to content

Conversation

owenca
Copy link
Contributor

@owenca owenca commented Oct 13, 2025

No description provided.

@owenca owenca added crash-on-valid regression:21 Regression in 21 release labels Oct 13, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 13, 2025

@llvm/pr-subscribers-clang-format

Author: owenca (owenca)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/163111.diff

2 Files Affected:

  • (modified) clang/lib/Format/Format.cpp (+2-1)
  • (modified) clang/unittests/Format/ConfigParseTest.cpp (+7)
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 686e54128d372..093e88ffcc85d 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -2184,8 +2184,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 6111e86ff7076..52f02c3ba8686 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -1264,6 +1264,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;

@owenca owenca added this to the LLVM 21.x Release milestone Oct 13, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Oct 13, 2025
@c-rhodes c-rhodes moved this from Needs Triage to Needs Backport PR in LLVM Release Status Oct 13, 2025
@github-project-automation github-project-automation bot moved this from Needs Backport PR to Needs Merge in LLVM Release Status Oct 16, 2025
@owenca owenca merged commit 059f2df into llvm:main Oct 17, 2025
14 checks passed
@owenca owenca deleted the empty-config branch October 17, 2025 04:41
@github-project-automation github-project-automation bot moved this from Needs Merge to Done in LLVM Release Status Oct 17, 2025
@owenca
Copy link
Contributor Author

owenca commented Oct 17, 2025

/cherry-pick 059f2df

@llvmbot
Copy link
Member

llvmbot commented Oct 17, 2025

Failed to cherry-pick: 059f2df

https://github.com/llvm/llvm-project/actions/runs/18582710285

Please manually backport the fix and push it to your github fork. Once this is done, please create a pull request

@owenca
Copy link
Contributor Author

owenca commented Oct 17, 2025

/cherry-pick d7921de 059f2df

@llvmbot
Copy link
Member

llvmbot commented Oct 17, 2025

/pull-request #163919

@owenca owenca removed the regression:21 Regression in 21 release label Oct 17, 2025
@owenca owenca removed this from the LLVM 21.x Release milestone Oct 17, 2025
@llvm llvm deleted a comment from llvm-ci Oct 17, 2025
c-rhodes pushed a commit to llvmbot/llvm-project that referenced this pull request Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

3 participants