@@ -3942,34 +3942,42 @@ tooling::Replacements sortUsingDeclarations(const FormatStyle &Style,
3942
3942
LangOptions getFormattingLangOpts (const FormatStyle &Style ) {
3943
3943
LangOptions LangOpts;
3944
3944
3945
- FormatStyle::LanguageStandard LexingStd = Style .Standard ;
3946
- if (LexingStd == FormatStyle::LS_Auto)
3947
- LexingStd = FormatStyle::LS_Latest;
3948
- if (LexingStd == FormatStyle::LS_Latest)
3945
+ auto LexingStd = Style .Standard ;
3946
+ if (LexingStd == FormatStyle::LS_Auto || LexingStd == FormatStyle::LS_Latest)
3949
3947
LexingStd = FormatStyle::LS_Cpp20;
3950
- LangOpts.CPlusPlus = 1 ;
3951
- LangOpts.CPlusPlus11 = LexingStd >= FormatStyle::LS_Cpp11;
3952
- LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14;
3953
- LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp17;
3954
- LangOpts.CPlusPlus20 = LexingStd >= FormatStyle::LS_Cpp20;
3955
- LangOpts.Char8 = LexingStd >= FormatStyle::LS_Cpp20;
3948
+
3949
+ const bool SinceCpp11 = LexingStd >= FormatStyle::LS_Cpp11;
3950
+ const bool SinceCpp20 = LexingStd >= FormatStyle::LS_Cpp20;
3951
+
3952
+ switch (Style .Language ) {
3953
+ case FormatStyle::LK_C:
3954
+ LangOpts.C17 = 1 ;
3955
+ break ;
3956
+ case FormatStyle::LK_Cpp:
3957
+ case FormatStyle::LK_ObjC:
3958
+ LangOpts.CXXOperatorNames = 1 ;
3959
+ LangOpts.CPlusPlus11 = SinceCpp11;
3960
+ LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14;
3961
+ LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp17;
3962
+ LangOpts.CPlusPlus20 = SinceCpp20;
3963
+ [[fallthrough]];
3964
+ default :
3965
+ LangOpts.CPlusPlus = 1 ;
3966
+ }
3967
+
3968
+ LangOpts.Char8 = SinceCpp20;
3956
3969
// Turning on digraphs in standards before C++0x is error-prone, because e.g.
3957
3970
// the sequence "<::" will be unconditionally treated as "[:".
3958
3971
// Cf. Lexer::LexTokenInternal.
3959
- LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11 ;
3972
+ LangOpts.Digraphs = SinceCpp11 ;
3960
3973
3961
3974
LangOpts.LineComment = 1 ;
3962
-
3963
- const auto Language = Style .Language ;
3964
- LangOpts.C17 = Language == FormatStyle::LK_C;
3965
- LangOpts.CXXOperatorNames =
3966
- Language == FormatStyle::LK_Cpp || Language == FormatStyle::LK_ObjC;
3967
-
3968
3975
LangOpts.Bool = 1 ;
3969
3976
LangOpts.ObjC = 1 ;
3970
3977
LangOpts.MicrosoftExt = 1 ; // To get kw___try, kw___finally.
3971
3978
LangOpts.DeclSpecKeyword = 1 ; // To get __declspec.
3972
3979
LangOpts.C99 = 1 ; // To get kw_restrict for non-underscore-prefixed restrict.
3980
+
3973
3981
return LangOpts;
3974
3982
}
3975
3983
0 commit comments