fodinabor updated this revision to Diff 312518. fodinabor added a comment. Add lit test to ensure behaviour of the -Wno-error=unkown flag.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D93459/new/ https://reviews.llvm.org/D93459 Files: 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/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 ;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits