[llvm-branch-commits] [cfe-branch] r301463 - Merging r299574:

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Apr 26 13:48:40 PDT 2017


Author: tstellar
Date: Wed Apr 26 15:48:39 2017
New Revision: 301463

URL: http://llvm.org/viewvc/llvm-project?rev=301463&view=rev
Log:
Merging r299574:

------------------------------------------------------------------------
r299574 | nico | 2017-04-05 14:10:42 -0400 (Wed, 05 Apr 2017) | 17 lines

clang-format: Support formatting utf-8 character literals in C++11+ mode.

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 at denis.gladkikh.email>!

------------------------------------------------------------------------

Modified:
    cfe/branches/release_40/docs/ClangFormatStyleOptions.rst
    cfe/branches/release_40/include/clang/Format/Format.h
    cfe/branches/release_40/lib/Format/Format.cpp
    cfe/branches/release_40/unittests/Format/FormatTest.cpp

Modified: cfe/branches/release_40/docs/ClangFormatStyleOptions.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/docs/ClangFormatStyleOptions.rst?rev=301463&r1=301462&r2=301463&view=diff
==============================================================================
--- cfe/branches/release_40/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/branches/release_40/docs/ClangFormatStyleOptions.rst Wed Apr 26 15:48:39 2017
@@ -734,7 +734,8 @@ the configuration (without a prefix: ``A
     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.

Modified: cfe/branches/release_40/include/clang/Format/Format.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/include/clang/Format/Format.h?rev=301463&r1=301462&r2=301463&view=diff
==============================================================================
--- cfe/branches/release_40/include/clang/Format/Format.h (original)
+++ cfe/branches/release_40/include/clang/Format/Format.h Wed Apr 26 15:48:39 2017
@@ -606,7 +606,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

Modified: cfe/branches/release_40/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/lib/Format/Format.cpp?rev=301463&r1=301462&r2=301463&view=diff
==============================================================================
--- cfe/branches/release_40/lib/Format/Format.cpp (original)
+++ cfe/branches/release_40/lib/Format/Format.cpp Wed Apr 26 15:48:39 2017
@@ -1845,6 +1845,7 @@ LangOptions getFormattingLangOpts(const
   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.Language == FormatStyle::LK_Cpp;
   LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;

Modified: cfe/branches/release_40/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/unittests/Format/FormatTest.cpp?rev=301463&r1=301462&r2=301463&view=diff
==============================================================================
--- cfe/branches/release_40/unittests/Format/FormatTest.cpp (original)
+++ cfe/branches/release_40/unittests/Format/FormatTest.cpp Wed Apr 26 15:48:39 2017
@@ -11053,6 +11053,20 @@ TEST_F(FormatTest, AllignTrailingComment
                    "/* comment 3 */         \\\n",
                    getLLVMStyleWithColumns(40)));
 }
+
+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




More information about the llvm-branch-commits mailing list