[PATCH] D146844: [clang-format] Handle '_' in ud-suffix for IntegerLiteralSeparator
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 24 13:31:39 PDT 2023
owenpan created this revision.
owenpan added reviewers: MyDeveloperDay, HazardyKnusperkeks, rymiel.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Fixes https://github.com/llvm/llvm-project/issues/61676.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D146844
Files:
clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
Index: clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
===================================================================
--- clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
+++ clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
@@ -47,6 +47,13 @@
Style.IntegerLiteralSeparator.Hex = 2;
verifyFormat("h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;", Hex, Style);
+ const StringRef UDL("u = 0xDEAD'BEEF'DE'AD'BEE'F_u64;");
+ verifyFormat("u = 0xDE'AD'BE'EF'DE'AD'BE'EF_u64;", UDL, Style);
+ Style.IntegerLiteralSeparator.Hex = -1;
+ verifyFormat("u = 0xDEADBEEFDEADBEEF_u64;", UDL, Style);
+ Style.IntegerLiteralSeparator.Hex = 0;
+ verifyFormat(UDL, Style);
+
verifyFormat("o0 = 0;\n"
"o1 = 07;\n"
"o5 = 012345",
Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
===================================================================
--- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -44,10 +44,13 @@
std::pair<tooling::Replacements, unsigned>
IntegerLiteralSeparatorFixer::process(const Environment &Env,
const FormatStyle &Style) {
+ std::string Suffix("uUlLzZn");
+
switch (Style.Language) {
case FormatStyle::LK_Cpp:
case FormatStyle::LK_ObjC:
Separator = '\'';
+ Suffix.push_back('_');
break;
case FormatStyle::LK_CSharp:
case FormatStyle::LK_Java:
@@ -116,7 +119,7 @@
continue;
}
const auto Start = Text[0] == '0' ? 2 : 0;
- auto End = Text.find_first_of("uUlLzZn");
+ auto End = Text.find_first_of(Suffix);
if (End == StringRef::npos)
End = Length;
if (Start > 0 || End < Length) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146844.508206.patch
Type: text/x-patch
Size: 1718 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230324/0ef7dc0b/attachment.bin>
More information about the cfe-commits
mailing list