[clang] [clang-format] Avoid crashing on malformed template closers in mustBreak (PR #173453)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 24 05:01:23 PST 2025


================
@@ -15421,6 +15421,22 @@ TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) {
   verifyFormat("class A:");
 }
 
+TEST_F(FormatTest, DoesNotCrashOnMalformedEnableIf) {
+  const char *Code =
+      "template <typename T, typename TIString>\n"
+      "typename etl::enable_if<etl::is_integral<T>::value &&\n"
+      "                        !etl::is_same<T, bool>::value>::value,\n"
+      "  const TIString& > ::type\n"
+      "to_string(const T value, TIString& str,\n"
+      "          const etl::basic_format_spec<TIString>& format,\n"
+      "          const bool append = false) {\n"
+      "}\n";
+  // Ensure formatting malformed template syntax doesn't assert, regardless of
+  // whether clang-format considers the input complete.
+  EXPECT_NO_FATAL_FAILURE(format(Code, std::nullopt, SC_DoNotCheck));
----------------
HazardyKnusperkeks wrote:

We have `verifyFormat` or `verifyNoCrash` at our hands.

https://github.com/llvm/llvm-project/pull/173453


More information about the cfe-commits mailing list