[clang] [clang-format] Disalbe IntegerLiteralSeparator for C++ before c++14 (PR #151273)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 29 23:22:25 PDT 2025
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/151273
>From 9fab68a7aa71e6ffe6ad6476359a21884b084576 Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Tue, 29 Jul 2025 21:09:46 -0700
Subject: [PATCH] [clang-format] Disalbe IntegerLiteralSeparator for C++ before
c++14
Fixes #151102
---
clang/lib/Format/IntegerLiteralSeparatorFixer.cpp | 11 +++++++----
.../unittests/Format/IntegerLiteralSeparatorTest.cpp | 3 +++
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
index 80487fa673bf0..7772a5619c4bd 100644
--- a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -45,15 +45,18 @@ std::pair<tooling::Replacements, unsigned>
IntegerLiteralSeparatorFixer::process(const Environment &Env,
const FormatStyle &Style) {
switch (Style.Language) {
- case FormatStyle::LK_Cpp:
- case FormatStyle::LK_ObjC:
- Separator = '\'';
- break;
case FormatStyle::LK_CSharp:
case FormatStyle::LK_Java:
case FormatStyle::LK_JavaScript:
Separator = '_';
break;
+ case FormatStyle::LK_Cpp:
+ case FormatStyle::LK_ObjC:
+ if (Style.Standard >= FormatStyle::LS_Cpp14) {
+ Separator = '\'';
+ break;
+ }
+ [[fallthrough]];
default:
return {};
}
diff --git a/clang/unittests/Format/IntegerLiteralSeparatorTest.cpp b/clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
index 8681c3d2f89ce..53b6dd8efadff 100644
--- a/clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
+++ b/clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
@@ -83,6 +83,9 @@ TEST_F(IntegerLiteralSeparatorTest, SingleQuoteAsSeparator) {
"d = 5678_km;\n"
"h = 0xDEF_u16;",
Style);
+
+ Style.Standard = FormatStyle::LS_Cpp11;
+ verifyFormat("ld = 1234L;", Style);
}
TEST_F(IntegerLiteralSeparatorTest, UnderscoreAsSeparator) {
More information about the cfe-commits
mailing list