mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #31099 from artemcm/NoWarningsAsErrorsOption
Add compiler option to *disable* warnings-as-errors
This commit is contained in:
@@ -528,6 +528,10 @@ def warnings_as_errors : Flag<["-"], "warnings-as-errors">,
|
||||
Flags<[FrontendOption]>,
|
||||
HelpText<"Treat warnings as errors">;
|
||||
|
||||
def no_warnings_as_errors : Flag<["-"], "no-warnings-as-errors">,
|
||||
Flags<[FrontendOption]>,
|
||||
HelpText<"Don't treat warnings as errors">;
|
||||
|
||||
def continue_building_after_errors : Flag<["-"], "continue-building-after-errors">,
|
||||
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
|
||||
HelpText<"Continue building, even after errors are encountered">;
|
||||
|
||||
@@ -140,7 +140,8 @@ static void validateBridgingHeaderArgs(DiagnosticEngine &diags,
|
||||
static void validateWarningControlArgs(DiagnosticEngine &diags,
|
||||
const ArgList &args) {
|
||||
if (args.hasArg(options::OPT_suppress_warnings) &&
|
||||
args.hasArg(options::OPT_warnings_as_errors)) {
|
||||
args.hasFlag(options::OPT_warnings_as_errors,
|
||||
options::OPT_no_warnings_as_errors, false)) {
|
||||
diags.diagnose(SourceLoc(), diag::error_conflicting_options,
|
||||
"-warnings-as-errors", "-suppress-warnings");
|
||||
}
|
||||
|
||||
@@ -216,7 +216,8 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
|
||||
inputArgs.AddLastArg(arguments, options::OPT_profile_generate);
|
||||
inputArgs.AddLastArg(arguments, options::OPT_profile_use);
|
||||
inputArgs.AddLastArg(arguments, options::OPT_profile_coverage_mapping);
|
||||
inputArgs.AddLastArg(arguments, options::OPT_warnings_as_errors);
|
||||
inputArgs.AddAllArgs(arguments, options::OPT_warnings_as_errors,
|
||||
options::OPT_no_warnings_as_errors);
|
||||
inputArgs.AddLastArg(arguments, options::OPT_sanitize_EQ);
|
||||
inputArgs.AddLastArg(arguments, options::OPT_sanitize_recover_EQ);
|
||||
inputArgs.AddLastArg(arguments, options::OPT_sanitize_coverage_EQ);
|
||||
|
||||
@@ -760,7 +760,8 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
|
||||
Opts.PCHDisableValidation |= Args.hasArg(OPT_pch_disable_validation);
|
||||
}
|
||||
|
||||
if (Args.hasArg(OPT_warnings_as_errors))
|
||||
if (Args.hasFlag(options::OPT_warnings_as_errors,
|
||||
options::OPT_no_warnings_as_errors, false))
|
||||
Opts.ExtraArgs.push_back("-Werror");
|
||||
|
||||
Opts.DebuggerSupport |= Args.hasArg(OPT_debugger_support);
|
||||
@@ -845,7 +846,9 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
|
||||
/*Default=*/llvm::sys::Process::StandardErrHasColors());
|
||||
Opts.FixitCodeForAllDiagnostics |= Args.hasArg(OPT_fixit_all);
|
||||
Opts.SuppressWarnings |= Args.hasArg(OPT_suppress_warnings);
|
||||
Opts.WarningsAsErrors |= Args.hasArg(OPT_warnings_as_errors);
|
||||
Opts.WarningsAsErrors = Args.hasFlag(options::OPT_warnings_as_errors,
|
||||
options::OPT_no_warnings_as_errors,
|
||||
false);
|
||||
Opts.PrintDiagnosticNames |= Args.hasArg(OPT_debug_diagnostic_names);
|
||||
Opts.PrintEducationalNotes |= Args.hasArg(OPT_print_educational_notes);
|
||||
Opts.EnableExperimentalFormatting |=
|
||||
|
||||
12
test/diagnostics/no_warnings_as_errors.swift
Normal file
12
test/diagnostics/no_warnings_as_errors.swift
Normal file
@@ -0,0 +1,12 @@
|
||||
// RUN: %target-swift-frontend -typecheck -warnings-as-errors -no-warnings-as-errors %s 2>&1 | %FileCheck %s --check-prefix=CHECK-WARNING
|
||||
// RUN: not %target-swift-frontend -typecheck -no-warnings-as-errors -warnings-as-errors %s 2>&1 | %FileCheck %s --check-prefix=CHECK-ERROR
|
||||
|
||||
|
||||
// This test verifies that the -no-warnings-as-errors option nullifies the effect of the -warnings-as-errors option
|
||||
// CHECK-WARNING-NOT: error: initialization of immutable value 'c' was never used;
|
||||
// CHECK-WARNING: warning: initialization of immutable value 'c' was never used;
|
||||
// CHECK-ERROR-NOT: warning: initialization of immutable value 'c' was never used;
|
||||
// CHECK-ERROR: error: initialization of immutable value 'c' was never used;
|
||||
func b() {
|
||||
let c = 2
|
||||
}
|
||||
Reference in New Issue
Block a user