[PATCH] D28844: clang-format: fix fallback style set to "none" not formatting

Antonio Maiorano via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 17 19:52:09 PST 2017


amaiorano added inline comments.


================
Comment at: lib/Format/Format.cpp:1906
 
-  // 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))
----------------
Technically, we don't need to initialize FallbackStyle to getNoStyle() here as the call to getPredefinedStyle just below will initialize it. Let me know what you would prefer here.


================
Comment at: test/Format/style-on-command-line.cpp:15
+// RUN: rm %T/_clang-format
+// RUN: clang-format -style=file -fallback-style=WebKit -assume-filename=%T/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK10 %s
+// RUN: clang-format -style=file -assume-filename=%T/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK11 %s
----------------
Tests no config file found, WebKit fallback style is applied


================
Comment at: test/Format/style-on-command-line.cpp:16
+// RUN: clang-format -style=file -fallback-style=WebKit -assume-filename=%T/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK10 %s
+// RUN: clang-format -style=file -assume-filename=%T/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK11 %s
+// RUN: clang-format -style=file -fallback-style=none -assume-filename=%T/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK12 %s
----------------
Tests no config file found, no fallback style, LLVM style is applied


================
Comment at: test/Format/style-on-command-line.cpp:17
+// RUN: clang-format -style=file -assume-filename=%T/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK11 %s
+// RUN: clang-format -style=file -fallback-style=none -assume-filename=%T/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK12 %s
 void f() {
----------------
Tests no config file found, fallback style set to "none", no formatting is applied


https://reviews.llvm.org/D28844





More information about the cfe-commits mailing list