Skip to content

Commit a72b064

Browse files
committed
[clang-format] Handle <chrono> ud suffixes in IntegerLiteralSeparator
Fixes llvm#62679. Differential Revision: https://reviews.llvm.org/D150539
1 parent ef1f27d commit a72b064

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
@@ -60,6 +60,24 @@ TEST_F(IntegerLiteralSeparatorTest, SingleQuoteAsSeparator) {
6060
"hil = 0xABCil;",
6161
Style);
6262

63+
verifyFormat("bd = 0b1'0000d;\n"
64+
"dh = 1'234h;\n"
65+
"dmin = 1'234min;\n"
66+
"dns = 1'234ns;\n"
67+
"ds = 1'234s;\n"
68+
"dus = 1'234us;\n"
69+
"hy = 0xA'BCy;",
70+
"bd = 0b10000d;\n"
71+
"dh = 1234h;\n"
72+
"dmin = 1234min;\n"
73+
"dns = 1234ns;\n"
74+
"ds = 1234s;\n"
75+
"dus = 1234us;\n"
76+
"hy = 0xABCy;",
77+
Style);
78+
79+
verifyFormat("hd = 0xAB'Cd;", "hd = 0xABCd;", Style);
80+
6381
verifyFormat("d = 5'678_km;\n"
6482
"h = 0xD'EF_u16;",
6583
"d = 5678_km;\n"

0 commit comments

Comments
 (0)