Skip to content

Commit

Permalink
[clang-format] Handle <chrono> ud suffixes in IntegerLiteralSeparator
Browse files Browse the repository at this point in the history
Fixes #62679.

Differential Revision: https://reviews.llvm.org/D150539
  • Loading branch information
owenca committed May 16, 2023
1 parent ef1f27d commit a72b064
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
Expand Up @@ -113,7 +113,11 @@ IntegerLiteralSeparatorFixer::process(const Environment &Env,
continue;
}
if (Style.isCpp()) {
if (const auto Pos = Text.find_first_of("_i"); Pos != StringRef::npos) {
// Hex alpha digits a-f/A-F must be at the end of the string literal.
StringRef Suffixes = "_himnsuyd";
if (const auto Pos =
Text.find_first_of(IsBase16 ? Suffixes.drop_back() : Suffixes);
Pos != StringRef::npos) {
Text = Text.substr(0, Pos);
Length = Pos;
}
Expand Down
18 changes: 18 additions & 0 deletions clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
Expand Up @@ -60,6 +60,24 @@ TEST_F(IntegerLiteralSeparatorTest, SingleQuoteAsSeparator) {
"hil = 0xABCil;",
Style);

verifyFormat("bd = 0b1'0000d;\n"
"dh = 1'234h;\n"
"dmin = 1'234min;\n"
"dns = 1'234ns;\n"
"ds = 1'234s;\n"
"dus = 1'234us;\n"
"hy = 0xA'BCy;",
"bd = 0b10000d;\n"
"dh = 1234h;\n"
"dmin = 1234min;\n"
"dns = 1234ns;\n"
"ds = 1234s;\n"
"dus = 1234us;\n"
"hy = 0xABCy;",
Style);

verifyFormat("hd = 0xAB'Cd;", "hd = 0xABCd;", Style);

verifyFormat("d = 5'678_km;\n"
"h = 0xD'EF_u16;",
"d = 5678_km;\n"
Expand Down

0 comments on commit a72b064

Please sign in to comment.