@@ -3942,34 +3942,42 @@ tooling::Replacements sortUsingDeclarations(const FormatStyle &Style,
39423942LangOptions getFormattingLangOpts (const FormatStyle &Style) {
39433943 LangOptions LangOpts;
39443944
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)
39493947 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;
39563969 // Turning on digraphs in standards before C++0x is error-prone, because e.g.
39573970 // the sequence "<::" will be unconditionally treated as "[:".
39583971 // Cf. Lexer::LexTokenInternal.
3959- LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11 ;
3972+ LangOpts.Digraphs = SinceCpp11 ;
39603973
39613974 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-
39683975 LangOpts.Bool = 1 ;
39693976 LangOpts.ObjC = 1 ;
39703977 LangOpts.MicrosoftExt = 1 ; // To get kw___try, kw___finally.
39713978 LangOpts.DeclSpecKeyword = 1 ; // To get __declspec.
39723979 LangOpts.C99 = 1 ; // To get kw_restrict for non-underscore-prefixed restrict.
3980+
39733981 return LangOpts;
39743982}
39753983
0 commit comments