forked from OSchip/llvm-project
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>! llvm-svn: 299574
This commit is contained in:
parent
4eb2eccb24
commit
dc06518ff4
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue