[llvm] e6ea5b3 - [LLVM] Update formatv() documentation to clarify no escape for `}`

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 22 15:31:11 PDT 2020


Author: Rahul Joshi
Date: 2020-07-22T15:30:40-07:00
New Revision: e6ea5b388b0d463dc9b5710d3f945387a0e4f206

URL: https://github.com/llvm/llvm-project/commit/e6ea5b388b0d463dc9b5710d3f945387a0e4f206
DIFF: https://github.com/llvm/llvm-project/commit/e6ea5b388b0d463dc9b5710d3f945387a0e4f206.diff

LOG: [LLVM] Update formatv() documentation to clarify no escape for `}`

- Update documentation to clarify that `}` does not need to be doubled up.
- Update `EscapedBrace` test case to test this behavior

Differential Revision: https://reviews.llvm.org/D83888

Added: 
    

Modified: 
    llvm/include/llvm/Support/FormatVariadic.h
    llvm/unittests/Support/FormatVariadicTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/FormatVariadic.h b/llvm/include/llvm/Support/FormatVariadic.h
index dfafc3ccb44e..094b054f773f 100644
--- a/llvm/include/llvm/Support/FormatVariadic.h
+++ b/llvm/include/llvm/Support/FormatVariadic.h
@@ -205,10 +205,10 @@ template <typename Tuple> class formatv_object : public formatv_object_base {
 //
 // The characters '{' and '}' are reserved and cannot appear anywhere within a
 // replacement sequence.  Outside of a replacement sequence, in order to print
-// a literal '{' or '}' it must be doubled -- "{{" to print a literal '{' and
-// "}}" to print a literal '}'.
+// a literal '{' it must be doubled as "{{".
 //
 // ===Parameter Indexing===
+//
 // `index` specifies the index of the parameter in the parameter pack to format
 // into the output.  Note that it is possible to refer to the same parameter
 // index multiple times in a given format string.  This makes it possible to

diff  --git a/llvm/unittests/Support/FormatVariadicTest.cpp b/llvm/unittests/Support/FormatVariadicTest.cpp
index e3754fbd1bf0..37946165e365 100644
--- a/llvm/unittests/Support/FormatVariadicTest.cpp
+++ b/llvm/unittests/Support/FormatVariadicTest.cpp
@@ -60,6 +60,18 @@ TEST(FormatVariadicTest, EscapedBrace) {
   ASSERT_EQ(1u, Replacements.size());
   EXPECT_EQ("{{{", Replacements[0].Spec);
   EXPECT_EQ(ReplacementType::Literal, Replacements[0].Type);
+
+  // } does not require doubling up.
+  Replacements = formatv_object_base::parseFormatString("}");
+  ASSERT_EQ(1u, Replacements.size());
+  EXPECT_EQ("}", Replacements[0].Spec);
+  EXPECT_EQ(ReplacementType::Literal, Replacements[0].Type);
+
+  // } does not require doubling up.
+  Replacements = formatv_object_base::parseFormatString("}}}");
+  ASSERT_EQ(1u, Replacements.size());
+  EXPECT_EQ("}}}", Replacements[0].Spec);
+  EXPECT_EQ(ReplacementType::Literal, Replacements[0].Type);
 }
 
 TEST(FormatVariadicTest, ValidReplacementSequence) {


        


More information about the llvm-commits mailing list