[clang] [clang-format] Fix crash on numeric literals with an incomplete exponent (PR #206594)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 1 00:45:57 PDT 2026


Gustas =?utf-8?q?Janušonis?= <janusonis.gustas at gmail.com>,
Gustas =?utf-8?q?Janušonis?= <janusonis.gustas at gmail.com>,LeGusto
 <janusonis.gustas at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/206594 at github.com>


================
@@ -340,6 +340,17 @@ TEST_F(NumericLiteralCaseTest, UnderScoreSeparatorLanguages) {
   verifyFormat("o = 0o0_10_010;", "o = 0O0_10_010;", Style);
 }
 
+TEST_F(NumericLiteralCaseTest, IncompleteLiteralDoesNotCrash) {
----------------
owenca wrote:

You should move the tests to `NumericLiteralInfoTest`, e.g.:
```diff
diff --git a/clang/unittests/Format/NumericLiteralInfoTest.cpp b/clang/unittests/Format/NumericLiteralInfoTest.cpp
index a892cfff531e..329c79c71e58 100644
--- a/clang/unittests/Format/NumericLiteralInfoTest.cpp
+++ b/clang/unittests/Format/NumericLiteralInfoTest.cpp
@@ -66,6 +66,14 @@ TEST_F(NumericLiteralInfoTest, FloatingPointLiteral) {
   EXPECT_TRUE(verifyInfo(NumericLiteralInfo("0xF.Fp-9_Pa"), 1, 3, 5, 8));
 }
 
+TEST_F(NumericLiteralInfoTest, InvalidNumericLiteral) {
+  EXPECT_TRUE(verifyInfo(NumericLiteralInfo("1e")));
+  EXPECT_TRUE(verifyInfo(NumericLiteralInfo("1.0e")));
+  EXPECT_TRUE(verifyInfo(NumericLiteralInfo("0x")));
+  EXPECT_TRUE(verifyInfo(NumericLiteralInfo("0x_")));
+  EXPECT_TRUE(verifyInfo(NumericLiteralInfo("0x1p")));
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
```

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


More information about the cfe-commits mailing list