@@ -401,6 +401,7 @@ template <> struct MappingTraits<FormatStyle::KeepEmptyLinesStyle> {
401401
402402template <> struct ScalarEnumerationTraits <FormatStyle::LanguageKind> {
403403 static void enumeration (IO &IO, FormatStyle::LanguageKind &Value) {
404+ IO.enumCase (Value, " C" , FormatStyle::LK_C);
404405 IO.enumCase (Value, " Cpp" , FormatStyle::LK_Cpp);
405406 IO.enumCase (Value, " Java" , FormatStyle::LK_Java);
406407 IO.enumCase (Value, " JavaScript" , FormatStyle::LK_JavaScript);
@@ -3957,7 +3958,12 @@ LangOptions getFormattingLangOpts(const FormatStyle &Style) {
39573958 LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11;
39583959
39593960 LangOpts.LineComment = 1 ;
3960- LangOpts.CXXOperatorNames = Style.isCpp ();
3961+
3962+ const auto Language = Style.Language ;
3963+ LangOpts.C17 = Language == FormatStyle::LK_C;
3964+ LangOpts.CXXOperatorNames =
3965+ Language == FormatStyle::LK_Cpp || Language == FormatStyle::LK_ObjC;
3966+
39613967 LangOpts.Bool = 1 ;
39623968 LangOpts.ObjC = 1 ;
39633969 LangOpts.MicrosoftExt = 1 ; // To get kw___try, kw___finally.
@@ -3982,6 +3988,8 @@ const char *StyleOptionHelpDescription =
39823988 " --style=\" {BasedOnStyle: llvm, IndentWidth: 8}\" " ;
39833989
39843990static FormatStyle::LanguageKind getLanguageByFileName (StringRef FileName) {
3991+ if (FileName.ends_with (" .c" ))
3992+ return FormatStyle::LK_C;
39853993 if (FileName.ends_with (" .java" ))
39863994 return FormatStyle::LK_Java;
39873995 if (FileName.ends_with_insensitive (" .js" ) ||
@@ -4039,6 +4047,8 @@ static FormatStyle::LanguageKind getLanguageByComment(const Environment &Env) {
40394047 continue ;
40404048
40414049 Text = Text.trim ();
4050+ if (Text == " C" )
4051+ return FormatStyle::LK_C;
40424052 if (Text == " Cpp" )
40434053 return FormatStyle::LK_Cpp;
40444054 if (Text == " ObjC" )
0 commit comments