]> granicus.if.org Git - clang/commitdiff
clang-format: Support formatting utf-8 character literals in C++11+ mode.
authorNico Weber <nicolasweber@gmx.de>
Wed, 5 Apr 2017 18:10:42 +0000 (18:10 +0000)
committerNico Weber <nicolasweber@gmx.de>
Wed, 5 Apr 2017 18:10:42 +0000 (18:10 +0000)
clang-format <<END
auto c1 = u8'a';
auto c2 = u'a';
END

Before:
  auto c1 = u8 'a';
  auto c2 = u'a';

Now:
  auto c1 = u8'a';
  auto c2 = u'a';

Patch from Denis Gladkikh <llvm@denis.gladkikh.email>!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299574 91177308-0d34-0410-b5e6-96231b3b80d8

docs/ClangFormatStyleOptions.rst
include/clang/Format/Format.h
lib/Format/Format.cpp
unittests/Format/FormatTest.cpp

index 89b44aa993a3297b69d3074ef05615a021ef0d90..a1c785690fa6cae957405258695825bede3c7fac 100644 (file)
@@ -1462,7 +1462,8 @@ the configuration (without a prefix: ``Auto``).
     Use C++03-compatible syntax.
 
   * ``LS_Cpp11`` (in configuration: ``Cpp11``)
-    Use features of C++11 (e.g. ``A<A<int>>`` instead of ``A<A<int> >``).
+    Use features of C++11, C++14 and C++1z (e.g. ``A<A<int>>`` instead of 
+    ``A<A<int> >``).
 
   * ``LS_Auto`` (in configuration: ``Auto``)
     Automatic detection based on the input.
index 47eacb50a35e953cd897f760d490461f3c1e474f..369ffa87962039dcc81d28f90ad216c8a44c4ccd 100644 (file)
@@ -1256,7 +1256,8 @@ struct FormatStyle {
   enum LanguageStandard {
     /// Use C++03-compatible syntax.
     LS_Cpp03,
-    /// Use features of C++11 (e.g. ``A<A<int>>`` instead of ``A<A<int> >``).
+    /// Use features of C++11, C++14 and C++1z (e.g. ``A<A<int>>`` instead of
+    /// ``A<A<int> >``).
     LS_Cpp11,
     /// Automatic detection based on the input.
     LS_Auto
index 27f5849b3949b0e2500310cac77efd17f1f43b4f..0e2da71343d5d69cf5f294aa5dbd8010a34ea160 100644 (file)
@@ -1894,6 +1894,7 @@ LangOptions getFormattingLangOpts(const FormatStyle &Style) {
   LangOpts.CPlusPlus = 1;
   LangOpts.CPlusPlus11 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
   LangOpts.CPlusPlus14 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
+  LangOpts.CPlusPlus1z = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
   LangOpts.LineComment = 1;
   bool AlternativeOperators = Style.isCpp();
   LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;
index 4280941c37557d08cb388207e4eaf72025c516f8..a5b3d068db5969c7589d0f615659aa940bd11b75 100644 (file)
@@ -10195,6 +10195,19 @@ TEST_F(ReplacementTest, SortIncludesAfterReplacement) {
   EXPECT_EQ(Expected, *Result);
 }
 
+TEST_F(FormatTest, UTF8CharacterLiteralCpp03) {
+  format::FormatStyle Style = format::getLLVMStyle();
+  Style.Standard = FormatStyle::LS_Cpp03;
+  // cpp03 recognize this string as identifier u8 and literal character 'a'
+  EXPECT_EQ("auto c = u8 'a';", format("auto c = u8'a';", Style));
+}
+
+TEST_F(FormatTest, UTF8CharacterLiteralCpp11) {
+  // u8'a' is a C++17 feature, utf8 literal character, LS_Cpp11 covers
+  // all modes, including C++11, C++14 and C++17
+  EXPECT_EQ("auto c = u8'a';", format("auto c = u8'a';"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang