From 7eb7507aeb3552400c8a1f4dc82bb2212260c0da Mon Sep 17 00:00:00 2001 From: Antonio Maiorano Date: Fri, 20 Jan 2017 01:22:42 +0000 Subject: clang-format: fix fallback style set to "none" not always formatting This fixes clang-format not formatting if fallback-style is explicitly set to "none", and either a config file is found or YAML is passed in without a "BasedOnStyle". With this change, passing "none" in these cases will have no affect, and LLVM style will be used as the base style. Differential Revision: https://reviews.llvm.org/D28844 llvm-svn: 292562 --- clang/lib/Format/Format.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'clang/lib/Format/Format.cpp') diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index e793d003ff6..82647b6b2e3 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1888,8 +1888,8 @@ static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) { } llvm::Expected getStyle(StringRef StyleName, StringRef FileName, - StringRef FallbackStyle, StringRef Code, - vfs::FileSystem *FS) { + StringRef FallbackStyleName, + StringRef Code, vfs::FileSystem *FS) { if (!FS) { FS = vfs::getRealFileSystem().get(); } @@ -1903,9 +1903,9 @@ llvm::Expected getStyle(StringRef StyleName, StringRef FileName, (Code.contains("\n- (") || Code.contains("\n+ ("))) Style.Language = FormatStyle::LK_ObjC; - // FIXME: If FallbackStyle is explicitly "none", format is disabled. - if (!getPredefinedStyle(FallbackStyle, Style.Language, &Style)) - return make_string_error("Invalid fallback style \"" + FallbackStyle.str()); + FormatStyle FallbackStyle = getNoStyle(); + if (!getPredefinedStyle(FallbackStyleName, Style.Language, &FallbackStyle)) + return make_string_error("Invalid fallback style \"" + FallbackStyleName); if (StyleName.startswith("{")) { // Parse YAML/JSON style from the command line. @@ -1977,7 +1977,7 @@ llvm::Expected getStyle(StringRef StyleName, StringRef FileName, return make_string_error("Configuration file(s) do(es) not support " + getLanguageName(Style.Language) + ": " + UnsuitableConfigFiles); - return Style; + return FallbackStyle; } } // namespace format -- cgit v1.2.3