From bbbe98c73ada0930e2c55544a023350b1e4822e8 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 5 Apr 2017 18:10:42 +0000 Subject: [PATCH] clang-format: Support formatting utf-8 character literals in C++11+ mode. clang-format <! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299574 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ClangFormatStyleOptions.rst | 3 ++- include/clang/Format/Format.h | 3 ++- lib/Format/Format.cpp | 1 + unittests/Format/FormatTest.cpp | 13 +++++++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/ClangFormatStyleOptions.rst b/docs/ClangFormatStyleOptions.rst index 89b44aa993..a1c785690f 100644 --- a/docs/ClangFormatStyleOptions.rst +++ b/docs/ClangFormatStyleOptions.rst @@ -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>`` instead of ``A >``). + Use features of C++11, C++14 and C++1z (e.g. ``A>`` instead of + ``A >``). * ``LS_Auto`` (in configuration: ``Auto``) Automatic detection based on the input. diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index 47eacb50a3..369ffa8796 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -1256,7 +1256,8 @@ struct FormatStyle { enum LanguageStandard { /// Use C++03-compatible syntax. LS_Cpp03, - /// Use features of C++11 (e.g. ``A>`` instead of ``A >``). + /// Use features of C++11, C++14 and C++1z (e.g. ``A>`` instead of + /// ``A >``). LS_Cpp11, /// Automatic detection based on the input. LS_Auto diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 27f5849b39..0e2da71343 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -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; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 4280941c37..a5b3d068db 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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 -- 2.50.1