@@ -3946,34 +3946,42 @@ tooling::Replacements sortUsingDeclarations(const FormatStyle &Style,
39463946LangOptions getFormattingLangOpts (const FormatStyle &Style) {
39473947 LangOptions LangOpts;
39483948
3949- FormatStyle::LanguageStandard LexingStd = Style.Standard ;
3950- if (LexingStd == FormatStyle::LS_Auto)
3951- LexingStd = FormatStyle::LS_Latest;
3952- if (LexingStd == FormatStyle::LS_Latest)
3949+ auto LexingStd = Style.Standard ;
3950+ if (LexingStd == FormatStyle::LS_Auto || LexingStd == FormatStyle::LS_Latest)
39533951 LexingStd = FormatStyle::LS_Cpp20;
3954- LangOpts.CPlusPlus = 1 ;
3955- LangOpts.CPlusPlus11 = LexingStd >= FormatStyle::LS_Cpp11;
3956- LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14;
3957- LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp17;
3958- LangOpts.CPlusPlus20 = LexingStd >= FormatStyle::LS_Cpp20;
3959- LangOpts.Char8 = LexingStd >= FormatStyle::LS_Cpp20;
3952+
3953+ const bool SinceCpp11 = LexingStd >= FormatStyle::LS_Cpp11;
3954+ const bool SinceCpp20 = LexingStd >= FormatStyle::LS_Cpp20;
3955+
3956+ switch (Style.Language ) {
3957+ case FormatStyle::LK_C:
3958+ LangOpts.C11 = 1 ;
3959+ break ;
3960+ case FormatStyle::LK_Cpp:
3961+ case FormatStyle::LK_ObjC:
3962+ LangOpts.CXXOperatorNames = 1 ;
3963+ LangOpts.CPlusPlus11 = SinceCpp11;
3964+ LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14;
3965+ LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp17;
3966+ LangOpts.CPlusPlus20 = SinceCpp20;
3967+ [[fallthrough]];
3968+ default :
3969+ LangOpts.CPlusPlus = 1 ;
3970+ }
3971+
3972+ LangOpts.Char8 = SinceCpp20;
39603973 // Turning on digraphs in standards before C++0x is error-prone, because e.g.
39613974 // the sequence "<::" will be unconditionally treated as "[:".
39623975 // Cf. Lexer::LexTokenInternal.
3963- LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11 ;
3976+ LangOpts.Digraphs = SinceCpp11 ;
39643977
39653978 LangOpts.LineComment = 1 ;
3966-
3967- const auto Language = Style.Language ;
3968- LangOpts.C17 = Language == FormatStyle::LK_C;
3969- LangOpts.CXXOperatorNames =
3970- Language == FormatStyle::LK_Cpp || Language == FormatStyle::LK_ObjC;
3971-
39723979 LangOpts.Bool = 1 ;
39733980 LangOpts.ObjC = 1 ;
39743981 LangOpts.MicrosoftExt = 1 ; // To get kw___try, kw___finally.
39753982 LangOpts.DeclSpecKeyword = 1 ; // To get __declspec.
39763983 LangOpts.C99 = 1 ; // To get kw_restrict for non-underscore-prefixed restrict.
3984+
39773985 return LangOpts;
39783986}
39793987
0 commit comments