diff options
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 3 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestProto.cpp | 6 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestTextProto.cpp | 4 |
3 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 248e2b58501..0d54208bbe9 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2425,6 +2425,9 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, if (Left.MatchingParen && Left.MatchingParen->is(TT_ProtoExtensionLSquare) && Right.isOneOf(tok::l_brace, tok::less)) return !Style.Cpp11BracedListStyle; + // A percent is probably part of a formatting specification, such as %lld. + if (Left.is(tok::percent)) + return false; } else if (Style.Language == FormatStyle::LK_JavaScript) { if (Left.is(TT_JsFatArrow)) return true; diff --git a/clang/unittests/Format/FormatTestProto.cpp b/clang/unittests/Format/FormatTestProto.cpp index 27ecde7f340..40a069b3f3d 100644 --- a/clang/unittests/Format/FormatTestProto.cpp +++ b/clang/unittests/Format/FormatTestProto.cpp @@ -432,5 +432,11 @@ TEST_F(FormatTestProto, FormatsOptionsExtensions) { "};"); } +TEST_F(FormatTestProto, NoSpaceAfterPercent) { + verifyFormat("option (MyProto.options) = {\n" + " key: %lld\n" + "};"); +} + } // end namespace tooling } // end namespace clang diff --git a/clang/unittests/Format/FormatTestTextProto.cpp b/clang/unittests/Format/FormatTestTextProto.cpp index 8786b270ed5..151774b9e2e 100644 --- a/clang/unittests/Format/FormatTestTextProto.cpp +++ b/clang/unittests/Format/FormatTestTextProto.cpp @@ -386,5 +386,9 @@ TEST_F(FormatTestTextProto, FormatsExtensions) { " }\n" "}"); } + +TEST_F(FormatTestTextProto, NoSpaceAfterPercent) { + verifyFormat("key: %d"); +} } // end namespace tooling } // end namespace clang |