summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2018-04-05 09:33:03 +0000
committerKrasimir Georgiev <krasimir@google.com>2018-04-05 09:33:03 +0000
commit44e2e9f1c5b755001fe32319d1cf933b77c0aef8 (patch)
tree8c7bdb39fea70c71e60e30ea3fe46ef69ab848e5 /clang/lib/Format
parentabba04886e1443af1993d80002f0d50945292684 (diff)
downloadbcm5719-llvm-44e2e9f1c5b755001fe32319d1cf933b77c0aef8.tar.gz
bcm5719-llvm-44e2e9f1c5b755001fe32319d1cf933b77c0aef8.zip
[clang-format] Preserve spaces before a percent in (text) protos
This makes sure that we do not change the meaning of pieces of text with format specifiers. llvm-svn: 329263
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index cdf921c3c65..c2d6875e0c3 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2518,6 +2518,10 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
// A percent is probably part of a formatting specification, such as %lld.
if (Left.is(tok::percent))
return false;
+ // Preserve the existence of a space before a percent for cases like 0x%04x
+ // and "%d %d"
+ if (Left.is(tok::numeric_constant) && Right.is(tok::percent))
+ return Right.WhitespaceRange.getEnd() != Right.WhitespaceRange.getBegin();
} else if (Style.Language == FormatStyle::LK_JavaScript) {
if (Left.is(TT_JsFatArrow))
return true;
OpenPOWER on IntegriCloud