8000 [clang-format] Handle <chrono> ud suffixes in IntegerLiteralSeparator · inside-compiler/llvm-project@35bd94a · GitHub
[go: up one dir, main page]

Skip to content

Commit 35bd94a

Browse files
owencatstellar
authored andcommitted
[clang-format] Handle <chrono> ud suffixes in IntegerLiteralSeparator
Fixes llvm#62679. Differential Revision: https://reviews.llvm.org/D150539 (cherry picked from commit a72b064)
1 parent 9d0a2a4 commit 35bd94a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

clang/lib/Format/IntegerLiteralSeparatorFixer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ IntegerLiteralSeparatorFixer::process(const Environment &Env,
113113
continue;
114114
}
115115
if (Style.isCpp()) {
116-
if (const auto Pos = Text.find_first_of("_i"); Pos != StringRef::npos) {
116+
// Hex alpha digits a-f/A-F must be at the end of the string literal.
117+
StringRef Suffixes = "_himnsuyd";
118+
if (const auto Pos =
119+
Text.find_first_of(IsBase16 ? Suffixes.drop_back() : Suffixes);
120+
Pos != StringRef::npos) {
117121
Text = Text.substr(0, Pos);
118122
Length = Pos;
119123
}

clang/unittests/Format/IntegerLiteralSeparatorTest.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,24 @@ TEST_F(IntegerLiteralSeparatorTest, SingleQuoteAsSeparator) {
110110
"hil = 0xABCil;",
111111
Style);
112112

113+
verifyFormat("bd = 0b1'0000d;\n"
114+
"dh = 1'234h;\n"
115+
"dmin = 1'234min;\n"
116+
"dns = 1'234ns;\n"
117+
"ds = 1'234s;\n"
118+
"dus = 1'234us;\n"
119+
"hy = 0xA'BCy;",
120+
"bd = 0b10000d;\n"
121+
"dh = 1234h;\n"
122+
"dmin = 1234min;\n"
123+
"dns = 1234ns;\n"
124+
"ds = 1234s;\n"
125+
"dus = 1234us;\n"
126+
"hy = 0xABCy;",
127+
Style);
128+
129+
verifyFormat("hd = 0xAB'Cd;", "hd = 0xABCd;", Style);
130+
113131
verifyFormat("d = 5'678_km;\n"
114132
"h = 0xD'EF_u16;",
115133
"d = 5678_km;\n"

0 commit comments

Comments
 (0)
0