From 295d429ca14e466be8d785ae4737fcf62a706918 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 12 Mar 2018 10:11:30 +0000 Subject: [PATCH] Don't re-format raw string literal contents when formatting is disable Not entirely sure this is the best place to put this check, but it fixes the immediate issue. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327253 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 2 +- unittests/Format/FormatTestRawStrings.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index d53cf808dd..000f82a021 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -1480,7 +1480,7 @@ unsigned ContinuationIndenter::handleEndOfLine(const FormatToken &Current, // Compute the raw string style to use in case this is a raw string literal // that can be reformatted. auto RawStringStyle = getRawStringStyle(Current, State); - if (RawStringStyle) { + if (RawStringStyle && !Current.Finalized) { Penalty = reformatRawStringLiteral(Current, State, *RawStringStyle, DryRun); } else if (Current.IsMultiline && Current.isNot(TT_BlockComment)) { // Don't break multi-line tokens other than block comments and raw string diff --git a/unittests/Format/FormatTestRawStrings.cpp b/unittests/Format/FormatTestRawStrings.cpp index daef6d7225..85f0aab871 100644 --- a/unittests/Format/FormatTestRawStrings.cpp +++ b/unittests/Format/FormatTestRawStrings.cpp @@ -164,6 +164,20 @@ t = R"pb(item:1)pb";)test", getRawStringPbStyleWithColumns(40))); } +TEST_F(FormatTestRawStrings, RespectsClangFormatOff) { + expect_eq(R"test( +// clang-format off +s = R"pb(item: 1)pb"; +// clang-format on +t = R"pb(item: 1)pb";)test", + format(R"test( +// clang-format off +s = R"pb(item: 1)pb"; +// clang-format on +t = R"pb(item: 1)pb";)test", + getRawStringPbStyleWithColumns(40))); +} + TEST_F(FormatTestRawStrings, ReformatsShortRawStringsOnSingleLine) { expect_eq( R"test(P p = TP(R"pb()pb");)test", -- 2.50.1