Skip to content

Commit 5fc482c

Browse files
authored
[clang-format] Disable IntegerLiteralSeparator for C++ before c++14 (#151273)
Fixes #151102
1 parent c9e2ad7 commit 5fc482c

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

clang/lib/Format/IntegerLiteralSeparatorFixer.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,18 @@ std::pair<tooling::Replacements, unsigned>
4545
IntegerLiteralSeparatorFixer::process(const Environment &Env,
4646
const FormatStyle &Style) {
4747
switch (Style.Language) {
48-
case FormatStyle::LK_Cpp:
49-
case FormatStyle::LK_ObjC:
50-
Separator = '\'';
51-
break;
5248
case FormatStyle::LK_CSharp:
5349
case FormatStyle::LK_Java:
5450
case FormatStyle::LK_JavaScript:
5551
Separator = '_';
5652
break;
53+
case FormatStyle::LK_Cpp:
54+
case FormatStyle::LK_ObjC:
55+
if (Style.Standard >= FormatStyle::LS_Cpp14) {
56+
Separator = '\'';
57+
break;
58+
}
59+
[[fallthrough]];
5760
default:
5861
return {};
5962
}

clang/unittests/Format/IntegerLiteralSeparatorTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ TEST_F(IntegerLiteralSeparatorTest, SingleQuoteAsSeparator) {
8383
"d = 5678_km;\n"
8484
"h = 0xDEF_u16;",
8585
Style);
86+
87+
Style.Standard = FormatStyle::LS_Cpp11;
88+
verifyFormat("ld = 1234L;", Style);
8689
}
8790

8891
TEST_F(IntegerLiteralSeparatorTest, UnderscoreAsSeparator) {

0 commit comments

Comments
 (0)