Skip to content

Commit 00e8ac3

Browse files
committedJul 24, 2019
[Format] Make it easy to add new format::FormatStyle::LanguageStandard. NFCI
Preparatory change for D65043. We current use `!=LS_Cpp03` to enable language standards 11,14,17, and 2a. `>=LS_Cpp11` is better if we decide to add new LanguageStandard in the future. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D65183 llvm-svn: 366876
1 parent 0e7bbb1 commit 00e8ac3

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed
 

‎clang/lib/Format/Format.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -2366,10 +2366,10 @@ tooling::Replacements sortUsingDeclarations(const FormatStyle &Style,
23662366
LangOptions getFormattingLangOpts(const FormatStyle &Style) {
23672367
LangOptions LangOpts;
23682368
LangOpts.CPlusPlus = 1;
2369-
LangOpts.CPlusPlus11 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
2370-
LangOpts.CPlusPlus14 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
2371-
LangOpts.CPlusPlus17 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
2372-
LangOpts.CPlusPlus2a = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
2369+
LangOpts.CPlusPlus11 = Style.Standard >= FormatStyle::LS_Cpp11;
2370+
LangOpts.CPlusPlus14 = Style.Standard >= FormatStyle::LS_Cpp11;
2371+
LangOpts.CPlusPlus17 = Style.Standard >= FormatStyle::LS_Cpp11;
2372+
LangOpts.CPlusPlus2a = Style.Standard >= FormatStyle::LS_Cpp11;
23732373
LangOpts.LineComment = 1;
23742374
bool AlternativeOperators = Style.isCpp();
23752375
LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;

‎clang/lib/Format/TokenAnnotator.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2859,7 +2859,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
28592859
(Style.Language == FormatStyle::LK_Proto && Left.is(TT_DictLiteral)))
28602860
return !Style.Cpp11BracedListStyle;
28612861
return Right.is(TT_TemplateCloser) && Left.is(TT_TemplateCloser) &&
2862-
(Style.Standard != FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
2862+
(Style.Standard < FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
28632863
}
28642864
if (Right.isOneOf(tok::arrow, tok::arrowstar, tok::periodstar) ||
28652865
Left.isOneOf(tok::arrow, tok::period, tok::arrowstar, tok::periodstar) ||
@@ -2878,7 +2878,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
28782878
return Right.WhitespaceRange.getBegin() != Right.WhitespaceRange.getEnd();
28792879
if (Right.is(tok::coloncolon) && !Left.isOneOf(tok::l_brace, tok::comment))
28802880
return (Left.is(TT_TemplateOpener) &&
2881-
Style.Standard == FormatStyle::LS_Cpp03) ||
2881+
Style.Standard < FormatStyle::LS_Cpp11) ||
28822882
!(Left.isOneOf(tok::l_paren, tok::r_paren, tok::l_square,
28832883
tok::kw___super, TT_TemplateCloser,
28842884
TT_TemplateOpener)) ||

0 commit comments

Comments
 (0)
Please sign in to comment.