summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Stellard <tstellar@redhat.com>2017-04-26 20:48:39 +0000
committerTom Stellard <tstellar@redhat.com>2017-04-26 20:48:39 +0000
commit555e77c84b2712de80610d3e1c851b5a2f182372 (patch)
treecfc1a82afb931bca7bb0e3c3e5e6da6f56a715a3
parent000bee063ea28cbabca5569c722b82d936991396 (diff)
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@denis.gladkikh.email>! ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_40@301463 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--docs/ClangFormatStyleOptions.rst3
-rw-r--r--include/clang/Format/Format.h3
-rw-r--r--lib/Format/Format.cpp1
-rw-r--r--unittests/Format/FormatTest.cpp14
4 files changed, 19 insertions, 2 deletions
diff --git a/docs/ClangFormatStyleOptions.rst b/docs/ClangFormatStyleOptions.rst
index 3f76da6dca..c0a6603575 100644
--- a/docs/ClangFormatStyleOptions.rst
+++ b/docs/ClangFormatStyleOptions.rst
@@ -734,7 +734,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.
diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h
index 6c6458b33d..3f9a76f660 100644
--- a/include/clang/Format/Format.h
+++ b/include/clang/Format/Format.h
@@ -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
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 389761d482..12cb555869 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -1845,6 +1845,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.Language == FormatStyle::LK_Cpp;
LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index b402b5c4a5..fb14a6b7c1 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -11053,6 +11053,20 @@ TEST_F(FormatTest, AllignTrailingComments) {
"/* 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