[PATCH] D93459: Fix -Wno-error= parsing in clang-format.
Joachim Meyer via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 17 13:00:59 PST 2020
fodinabor updated this revision to Diff 312596.
fodinabor added a comment.
Update ClangFormat.rst.
This is manually well formatted.. will try to make a new patch in the coming days to actually fix it in the support library.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93459/new/
https://reviews.llvm.org/D93459
Files:
clang/docs/ClangFormat.rst
clang/test/Format/error-config.cpp
clang/tools/clang-format/ClangFormat.cpp
Index: clang/tools/clang-format/ClangFormat.cpp
===================================================================
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -104,18 +104,6 @@
"SortIncludes style flag"),
cl::cat(ClangFormatCategory));
-// using the full param name as Wno-error probably won't be a common use case in
-// clang-format
-static cl::opt<bool> AllowUnknownOptions(
- "Wno-error=unknown",
- cl::desc("If set, unknown format options are only warned about.\n"
- "This can be used to enable formatting, even if the\n"
- "configuration contains unknown (newer) options.\n"
- "Use with caution, as this might lead to dramatically\n"
- "differing format depending on an option being\n"
- "supported or not."),
- cl::init(false), cl::cat(ClangFormatCategory));
-
static cl::opt<bool>
Verbose("verbose", cl::desc("If set, shows the list of processed files"),
cl::cat(ClangFormatCategory));
@@ -156,6 +144,23 @@
cl::desc("If set, changes formatting warnings to errors"),
cl::cat(ClangFormatCategory));
+namespace {
+enum class WNoError { Unknown };
+}
+
+static cl::bits<WNoError> WNoErrorList(
+ "Wno-error",
+ cl::desc("If set don't error out on the specified warning type."),
+ cl::values(
+ clEnumValN(WNoError::Unknown, "unknown",
+ "If set, unknown format options are only warned about.\n"
+ "This can be used to enable formatting, even if the\n"
+ "configuration contains unknown (newer) options.\n"
+ "Use with caution, as this might lead to dramatically\n"
+ "differing format depending on an option being\n"
+ "supported or not.")),
+ cl::cat(ClangFormatCategory));
+
static cl::opt<bool>
ShowColors("fcolor-diagnostics",
cl::desc("If set, and on a color-capable terminal controls "
@@ -391,7 +396,7 @@
llvm::Expected<FormatStyle> FormatStyle =
getStyle(Style, AssumedFileName, FallbackStyle, Code->getBuffer(),
- nullptr, AllowUnknownOptions.getValue());
+ nullptr, WNoErrorList.isSet(WNoError::Unknown));
if (!FormatStyle) {
llvm::errs() << llvm::toString(FormatStyle.takeError()) << "\n";
return true;
Index: clang/test/Format/error-config.cpp
===================================================================
--- /dev/null
+++ clang/test/Format/error-config.cpp
@@ -0,0 +1,11 @@
+// RUN: clang-format %s --Wno-error=unknown --style="{UnknownKey: true}" 2>&1 | FileCheck %s -check-prefix=CHECK
+// RUN: not clang-format %s --style="{UnknownKey: true}" 2>&1 | FileCheck %s -check-prefix=CHECK-FAIL
+
+// CHECK: YAML:1:2: warning: unknown key 'UnknownKey'
+// CHECK-NEXT: {UnknownKey: true}
+// CHECK-NEXT: ^~~~~~~~~~
+// CHECK-FAIL: YAML:1:2: error: unknown key 'UnknownKey'
+// CHECK-FAIL-NEXT: {UnknownKey: true}
+// CHECK-FAIL-NEXT: ^~~~~~~~~~
+
+int i ;
Index: clang/docs/ClangFormat.rst
===================================================================
--- clang/docs/ClangFormat.rst
+++ clang/docs/ClangFormat.rst
@@ -31,12 +31,13 @@
Clang-format options:
--Werror - If set, changes formatting warnings to errors
- --Wno-error=unknown - If set, unknown format options are only warned about.
- This can be used to enable formatting, even if the
- configuration contains unknown (newer) options.
- Use with caution, as this might lead to dramatically
- differing format depending on an option being
- supported or not.
+ --Wno-error=<value> - If set don't error out on the specified warning type.
+ =unknown - If set, unknown format options are only warned about.
+ This can be used to enable formatting, even if the
+ configuration contains unknown (newer) options.
+ Use with caution, as this might lead to dramatically
+ differing format depending on an option being
+ supported or not.
--assume-filename=<string> - Override filename used to determine the language.
When reading from stdin, clang-format assumes this
filename to determine the language.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93459.312596.patch
Type: text/x-patch
Size: 4660 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201217/85296cc6/attachment-0001.bin>
More information about the cfe-commits
mailing list